var count = 0;
var nz = /^[0-9]*[1-9][0-9]*$/;// 正整数；
var n = /^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;// 正浮点数 ；
var validFlg; // 校验标志
var validRestult;// 校验提示结果
var xiyaochangdu = [];
var zhongyaochangdu;
var cam1Map = {};// 手动添加的疾病

var vbu09;// 会员卡密码
var vajList = [];// 本次费用记录
var totalVbi = 0.0;// 本次总消费金额
var printList;
var zhenjin_index;
// sendAdviceImmediately();
// 确认医嘱
var thisbutton;
var savePrintList = [];
var t1;
function saveAdvice(that,isSend)
{
    kucunsendFlag = true;
    t1 = new Date().getTime();
    thisbutton = that;
    $(thisbutton).attr("disabled",true);
    execIframe();
    if (isSend == "send")
    {
        layer.msg('发送中....',
            {
                icon : 16,
                skin : 'layui-layer-msg16',
                shade : [
                    0.1, '#393D49'
                ],
                time : 0
            });
    }
    else
    {
        layer.msg('保存中....',
            {
                icon : 16,
                skin : 'layui-layer-msg16',
                shade : [
                    0.1, '#393D49'
                ],
                time : 0
            });
    }
    if (valueArr["p_100_105002_411"]=="1"){

        var chengdu = chengduNeed();
        if(!chengdu.isRight){
            $('#new_order_list a[href="#'+chengdu.curT+'"]').trigger("click");
            layer.msg(chengdu.msg,{
                time : 5000,
                icon : 0,
                skin : 'layui-layer-msg0'});
            $(thisbutton).removeAttr("disabled");
            return false;
        }
    }
    var illageflag = false;
    $("#new_order_list").find("li").find(".messageSign").each(function(ind,ele){
        if($(ele).is(":visible")&&$(ele)[0].style.backgroundColor == "red"){
            illageflag = true;
            return false;
        }
    })

    if(illageflag){
        layer.msg('请检查手工输入的医嘱!',{
            time : 2000,
            icon : 0,
            skin : 'layui-layer-msg0'});
        $(thisbutton).removeAttr("disabled");
        return false;
    }
    validFlg = true;
    validRestult = '';
    zhongyaochangdu = 0;
    // 编辑前删除
    var vaf01s = "";
    var cbm01 = $("#cbm01").val();
    if (cbm01)
    {
        var editArr = $(window.parent.document).find(".yizhu_details");
        for (var i = 0; i < editArr.length; i++)
        {
            var editStr = $(editArr[i]).attr("data-info");
            if(editStr){
                var editObj = JSON.parse(editStr);
                if (editObj.cbm01 == cbm01)
                {
                    vaf01s += editObj.vaf01 + ",";
                }

            }
        }
        var url = rootUrl + "/clideladvice/removeAdvice";
        var data =
            {
                "vaf01s" : vaf01s,
                "bce03" : bce03
            };

        $.ajax(
            {
                url : url,
                type : "post",
                data : data,
                async : false,
                dataType : 'json',
                success : function(data)
                {
                }
            });

    }

    // 西药
    var bby01Arr_1 = [];
    var bby01Arr_11 = [];// 储存西、成药品需要数量和库存数量的json数组

    var xiyao_tables = $(".left-content").find(".xiyao_table");
    $(xiyao_tables).each(function(x){
        var tableObj = $(this);
        $(tableObj).find("tbody tr").each(function()
        {
            var bby01 = $(this).find(".xiyao_yznr").next().next().val();
            if (bby01 != "" && bby01 != undefined)
            {
                var ypmc = $(this).find(".xiyao_yznr").val().replace(/[\r\n]/g,"");
                var vaf21 = $(this).find(".xiyao_zl").val(); // 数量
                var temp = {};
                temp.bby01 = bby01;
                temp.vaf21 = vaf21;
                temp.ypmc = ypmc;
                temp.zxks = $(this).find(".xiyao_zxks").attr("id");
                bby01Arr_11.push(temp);
                bby01Arr_1.push(temp);
            }
        });
    });

    // 中药
    var zhongyao_tables = $(".left-content").find(".zhongyao_table");
    $(zhongyao_tables).each(function(x){
        var tableObj = $(this);
        $(tableObj).find("tr").each(function()
        {
            var bby01 = $(this).find(".zhongyao_yznr").next().next().val();
            if (bby01 != "" && bby01 != undefined)
            {
                var vaf21 = $(this).find(".zhongyao_zl").val(); // 中药数量
                var ypmc = $(this).find(".zhongyao_yznr").val().replace(/[\r\n]/g,"");
                var temp = {};
                temp.bby01 = bby01;
                temp.vaf21 = vaf21;
                temp.ypmc = ypmc;
                temp.zxks = $(this).parents(".china_medicine").find(".china_medicine_com").find(".zhongyao_zxks select").val();
                bby01Arr_11.push(temp);
                bby01Arr_1.push(temp);
            }
        });
    });

    //材料
    var bby01Arr_4 = [];
    var bby01Arr_41 = [];// 储存材料需要数量和库存数量的json数组
    var cailiao_tables = $(".left-content").find(".cailiao_table");
    $(cailiao_tables).each(function(x){
        var tableObj = $(this);
        $(tableObj).find("tr").each(function()
        {
            var bby01 = $(this).find(".cailiao_yznr").next().next().val();
            if (bby01 != "" && bby01 != undefined)
            {
                var vaf21 = $(this).find(".cailiao_zl").val(); // 材料数量
                var zxks = $(this).find(".cailiao_zxks").val(); // 材料执行科室
                var ypmc = $(this).find(".cailiao_yznr").val().replace(/[\r\n]/g,"");
                var temp = {};
                temp.bby01 = bby01;
                temp.vaf21 = vaf21;
                temp.ypmc = ypmc;
                temp.zxks = zxks;
                bby01Arr_41.push(temp);
                bby01Arr_4.push(temp);
            }
        });
    });
    var msg = "";// 库存不够时的提示信息
    var kucuiFlag = true;
    if (valueArr['p_9999_9999_106']=='1')
    {
        $.ajax(
            {
                url : rootUrl + "/doctoradviceeditor/checkdrugstoreNew_cailiao",
                data :
                    {
                        bck01_c : valueArr['p_100_105002_404']=="-1"?bck01:valueArr['p_100_105002_404'],
                        lACF01 : 1,
                        bby01Arr_4 : JSON.stringify(bby01Arr_4)
                    },
                dataType : "json",
                type : "post",
                async : false,
                success : function(data)
                {
                    var list = data.list;
                    for (var i = 0; i < list.length; i++)
                    {
                        for (var j = 0; j < bby01Arr_41.length; j++)
                        {
                            if (bby01Arr_41[j]["bby01"] == list[i]["bby01"])
                            {
                                bby01Arr_41[j].amount = list[i]["amount"];
                                bby01Arr_41[j].bby03 = list[i]["bby03"];
                            }
                        }
                    }
                    for (var i = 0; i < bby01Arr_41.length; i++)
                    {
                        if (!bby01Arr_41[i]["amount"])
                        {
                            msg += bby01Arr_4[i]["ypmc"] + "--需要数量为" + bby01Arr_41[i]["vaf21"] + ",当前库存数量为0;<br/>";
                        }
                        else if ((Number(bby01Arr_41[i]["amount"]) < Number(bby01Arr_41[i]["vaf21"])))
                        {
                            console.log(bby01Arr_41[i]);
                            msg += bby01Arr_41[i]["ypmc"] + "--需要数量为" + bby01Arr_41[i]["vaf21"] + ",当前库存数量为" + bby01Arr_41[i]["amount"] + ";<br/>";
                        }
                    }
                    if ("" != msg)
                    {
                        kucuiFlag = false;
                        layer.alert(msg,
                            {
                                title : '库存不足提示'
                            });
                        $(thisbutton).removeAttr("disabled");
                    }
                }
            });
    }
    // 确认医嘱前检验药品库存是否足够
    var url = rootUrl + "/doctoradviceeditor/checkdrugstoreNew";
    var params = {bck01_x:valueArr['p_100_105002_108'],bck01_z:valueArr['p_100_105002_110']};
    params.lACF01 = 1;
    params.bby01Arr_1 = JSON.stringify(bby01Arr_1);

    $.post(url, params, function(data)
    {
        var list = data.list;
        for (var i = 0; i < list.length; i++)
        {
            for (var j = 0; j < bby01Arr_11.length; j++)
            {
                if (bby01Arr_11[j]["bby01"] == list[i]["bby01"])
                {
                    bby01Arr_11[j].amount = list[i]["amount"];
                    bby01Arr_11[j].bby03 = list[i]["bby03"];
                }
            }
        }
        for (var i = 0; i < bby01Arr_11.length; i++)
        {
            if (!bby01Arr_11[i]["amount"])
            {
                msg += bby01Arr_1[i]["ypmc"] + "--需要数量为" + bby01Arr_11[i]["vaf21"] + ",当前库存数量为0;<br/>";
            }
            else if ((Number(bby01Arr_11[i]["amount"]) < Number(bby01Arr_11[i]["vaf21"])))
            {
                console.log(bby01Arr_11[i]);
                msg += bby01Arr_11[i]["ypmc"] + "--需要数量为" + bby01Arr_11[i]["vaf21"] + ",当前库存数量为" + bby01Arr_11[i]["amount"] + ";<br/>";
            }
        }
        if ("" == msg) {
            // 数据合法性校验
            if (kucuiFlag) {
                var t6 = new Date().getTime();
                console.log('库存校验耗时' + (t6 - t1) + '毫秒');
                saveAdviceBegin(isSend);
            }

        } else {
            layer.alert(msg,
                {
                    title: '库存不足提示'
                });
            $(thisbutton).removeAttr("disabled");
        }
    });
}

function saveAdviceBegin(isSend)
{
    var bck01a = bck01;
    // 组装json
    var cbm1 = [];
    var vao1 = [];
    var vaf1 = [];
    var vbq1 = [];
    var vax1 = [];
    var vbf1 = [];
    var advice_details = [];//智慧医保audit
    var vaoLength = $(".bootstrap-tagsinput").children("span").length;
    /*
     * 手动诊断前先保存为疾病信息
     */
    var jibingArr = [];
    for (var i = 0; i < vaoLength; i++)
    {
        var id = $($(".bootstrap-tagsinput").children("span")[i]).attr("data-info");
        if (id == -999)
        {
            var cam1 = {};
            var temp = $($(".bootstrap-tagsinput").children("span")[i]).text();
            cam1.cam02 = 1;
            cam1.cam04 = temp;// 名称
            cam1.cam06 = bce03;// 编者
            cam1.abbrp = makePy(temp)[0];// 中文转换为拼音首字母
            jibingArr.push(cam1);
        }
    }
    debugger;
    // 西药
    var isxiyaochangdu = false;
    var xiyao_tables = $(".left-content").find(".xiyao_table");
    var totalLength = valueArr.p_100_105002_146;
    $(xiyao_tables).each(function(x){
        var tableId = $(this).attr("id");
        xiyaochangdu.length = 0;
        GetInfoFromTable1(tableId,vaf1, cbm1, vax1, vao1,advice_details);
        //去重
        xiyaochangdu = xiyaochangdu.unique2();//去重
        if (xiyaochangdu.length > totalLength)
        {
            isxiyaochangdu = true;

        }
    });
    if(isxiyaochangdu){
        var index = layer.alert('每个医嘱单限制药品条数最多为'+totalLength+'条，若要更改，可在参数设置中更改设置！',
            {
                skin : '#fff', // 样式类名
                closeBtn : 0
            }, function()
            {
                layer.close(index);
            });
        $(thisbutton).removeAttr("disabled");
        return false;
    }
    // 中药
    var zhongyao_tables = $(".left-content").find(".zhongyao_table");
    $(zhongyao_tables).each(function(x,ele){
//		var tableId = $(this).find("tbody").attr("id");
        GetInfoFromTable3(ele,vaf1, cbm1, vax1, vao1,advice_details);
    });
    //药品处方没有诊断的校验
    if(vaf1.length>0 && vao1.length==0)
    {
        layer.msg('药品处方无诊断不能保存！',{time:3000,icon:0,skin: 'layui-layer-msg0'});
        $(thisbutton).removeAttr("disabled");
        return true;
    }
    // 检验
    var jianyan_tables = $(".left-content").find(".jianyan_table");
    $(jianyan_tables).each(function(x){
        var tableId = $(this).attr("id");
        GetInfoFromTableL(tableId,vaf1, cbm1, vax1, vao1,advice_details);
    });
    // 检查
    var jiancha_tables = $(".left-content").find(".jiancha_table");
    $(jiancha_tables).each(function(x){
        var tableId = $(this).attr("id");
        GetInfoFromTableE(tableId,vaf1, cbm1, vax1, vao1, vbq1,advice_details);
    });
    // 手术
    var shoushu_tables = $(".left-content").find(".shoushu_table");
    $(shoushu_tables).each(function(x){
        var tableId = $(this).attr("id");
        GetInfoFromTableS(tableId,vaf1, cbm1, vax1, vao1,vbf1,advice_details);
    });
    // 治疗
    var zhiliao_tables = $(".left-content").find(".zhiliao_table");
    $(zhiliao_tables).each(function(x){
        var tableId = $(this).attr("id");
        GetInfoFromTableT(tableId,vaf1, cbm1, vax1, vao1,advice_details);
    });
    // 材料
    var cailaio_tables = $(".left-content").find(".cailiao_table");
    $(cailaio_tables).each(function(x){
        var tableId = $(this).attr("id");
        GetInfoFromTable4(tableId,vaf1, cbm1, vax1, vao1,advice_details);
    });

    if (valueArr.p_100_105002_354 == "1")
    {
        if (xiyaochangdu && zhongyaochangdu)
        {
            var index = layer.alert('医嘱单不允许对应多个药房，若要对应，可在参数设置中更改设置！',
                {
                    skin : '#fff', // 样式类名
                    closeBtn : 0
                }, function()
                {
                    layer.close(index);
                });
            return;
            $(thisbutton).removeAttr("disabled");
            // layer.msg("医嘱单不允许对应多个药房，若要对应，可在参数设置中更改设置！",{ time: 2000,icon: 0})
        }
    }
    var lxml = {};
    lxml.vao1 = vao1;
    lxml.vaf1 = vaf1;
    lxml.cbm1 = cbm1;
    lxml.vax1 = vax1;
    lxml.vbq1 = vbq1;
    lxml.vbf1 = vbf1;

    var data1 = {};
    data1.lxml = JSON.stringify(lxml);
    data1.ltype = 1;
    data1.lmode = 0;
    data1.lacf01 = 1;
    data1.lbck01 = bck01a;
    data1.lbce01 = bce01;
    data1.lbce02 = 1;
    data1.lbce03 = bce03;
    data1.rcbm = '';
    data1.lCBM01A = 0;
    console.table(vaf1);
    //调用智慧医保接口：audit
    audit(advice_details,vaf1,data1,isSend);

}

/**
 * 智慧医保校验完后开始保存医嘱
 * @param vaf1
 * @param data1
 */
function afterAudit(vaf1,data1,isSend)
{
    if (!validFlg)
    {
        if(validRestult)
        {
            layer.msg(validRestult,
                {
                    time : 3000,
                    icon : 2,
                    skin : 'layui-layer-msg2'
                });
        }

        $(thisbutton).removeAttr("disabled");
    }
    else
    {

        // 处方金额大于？时，处理办法。。。
        /*
         * var allTotal = 0; for(var i = 0;i<cbm1.length;i++) { allTotal +=
         * cbm1[i]["total"]; }
         */
        if (vaf1.length == 0)
        {
            layer.msg('没有需要保存的医嘱，请检查！',
                {
                    time : 2000,
                    icon : 0,
                    skin : 'layui-layer-msg0'
                });
            $(thisbutton).removeAttr("disabled");
        }
        /*
         * else if(allTotal > valueArr['p_100_105002_169']) {
         * layer.msg('处方限制金额为：'+valueArr['p_100_105002_169'], { time : 2000,
         * icon : 3 }); }
         */
        else
        {
            var t3 = new Date().getTime();
            data1.rcbm = (t3-t1);
            console.log('智慧医保和数据校验耗时'+(t3-t1)+'毫秒');
            //开始保存医嘱
            var obj = {};
            obj.data1 = data1;
            obj.isSend = isSend;
            sendAdviceByzhenjin(obj);
//			$.ajax(
//			{
//			url : rootUrl + "/clinewadvice/clinicvaf1insert",
//			type : "post",
//			async : false,
//			data : data1,
//			dataType : 'json',
//			success : function(data)
//			{
//				var t4 = new Date().getTime();
//			    console.log('保存遗嘱耗时'+(t4-t3)+'毫秒');
//				if (data.result == "Success")
//				{
//					var list = data.list;
//					if (isSend == "send")
//					{
//							if (valueArr['p_9999_9999_104']=="1")
//							{
//								// 发送使用...
//								zhenjin2(list);
//							}
//							else
//							{
//								var zjAddList = [];
//
//								sendImmediately(list,zjAddList);
//								var t5 = new Date().getTime();
//							    console.log('发送遗嘱耗时'+(t5-t4)+'毫秒');
//							}
//					}
//					else
//					{
//						layer.msg("保存成功！",
//						{
//						time : 2000,
//						icon : 1,
//						skin : 'layui-layer-msg1'
//						});
//						// 关闭并刷新
//						closeAndRefresh();
//					}
//				}
//				else
//				{
//					layer.msg(data.resultMsg,
//					{
//					icon : 0,
//					skin : 'layui-layer-msg0',
//					time : 3000
//					});
//					$(thisbutton).removeAttr("disabled");
//				}
//
//			}
//			});
        }
    }
}
// 直接发送
// 计算处方总价
function zongjia()
{
    // var
}

/**
 * 直接发送医嘱
 *
 * @param list
 */
function sendImmediately(obj)
{
    totalVbi = 0.0;
    var list = obj.list,zjAddList = obj.zjAddList;
    var senArr = [];
    var vbd1 = [];
    var vaf01s = "(";
    var vaf1 = "[";
    var cbm01Arr = [];
    var failureDelVaf01s = "";
    for (var i = 0; i < list.length; i++)
    {
        failureDelVaf01s += ","+list[i].vaf01;
        if (list[i].bda01 == "T" && list[i].vaf32 == "0")
        {
            senArr.push(list[i])
        }
        else if (list[i].bda01 != "T" && list[i].bda01 != "3")
        {
            senArr.push(list[i])
        }
    }
    if (failureDelVaf01s.length>0)
    {
        failureDelVaf01s = failureDelVaf01s.substring(1, failureDelVaf01s.length);
    }
    if (senArr)
    {
        var cbm01Arr_send = [];// 生成计价信息用
        for (var i = 0; i < senArr.length; i++)
        {
            var bda01 = senArr[i].bda01;
            var vaf01a = senArr[i].vaf01a;
            var vaf32 = senArr[i].vaf32;
            if (judgeFlag(bda01, vaf01a, vaf32))
            {
                var vaf01 = senArr[i].vaf01;
                vaf1 += "{";
                vaf1 += "\"vaf01\":" + vaf01;
                var vaf10 = senArr[i].vaf10;
                var bda01 = senArr[i].bda01;
                var bby01 = senArr[i].bby01;
                var bby25 = senArr[i].bby25;
                var dsk01 = senArr[i].dsk01;
                var bck01b = senArr[i].bck01b;
                var cbm01 = senArr[i].cbm01;
                cbm01Arr_send.push(cbm01);
                if ("LE".indexOf(bda01) >= 0)
                {
                    var obj = {};
                    obj.cbm01 = cbm01;
                    obj.bda01 = bda01;
                    cbm01Arr.push(obj);
                }
                if (i > 0)
                {
                    vaf01s += "," + vaf01;
                }
                else
                {
                    vaf01s += vaf01;
                }
                vaf1 += "}";
                // -----------------------------------------

                if (i < senArr.length - 1)
                {
                    vaf1 += ",";
                }
            }
        }
        cbm01Arr_send = cbm01Arr_send.unique2();// 去重
        for (var i = 0; i < cbm01Arr_send.length; i++)
        {
            vbdInfoForsend_final(cbm01Arr_send[i]);
            for (var j = 0; j < vbdList.length; j++)
            {
                var vbdT = {};
                vbdT.vaf01 = vbdList[j]["vaf01"];
                vbdT.bby01 = vbdList[j]["bby01"];
                vbdT.vbd04 = vbdList[j]["vaf21"];// 数量
                vbdT.bby25 = vbdList[j]['bby25'];// 剂量单价
                totalVbi += parseFloat($("#bencidaijie").text());//遍历累加消费金额
                vbdT.vbd05 = vbdList[j]['lprice'];// 门诊包装单价
                vbdT.vbd06 = vbdList[j]['bdu06'];// 是否有从项
                vbdT.bck01 = vbdList[j]['bck01'];// 执行科室
                vbdT.bdn01 = vbdList[j]['bdn01'];// 医嘱项目类型
                vbdT.vbd08 = vbdList[j]['bdu07'];// 费用性质
                vbdT.vbd09 = vbdList[j]['bdu10'];// 收费方式
                vbdT.dsk01 = vbdList[j]['dsk01'];// 药品批次
                vbdT.bby01a = vbdList[j]['bby01a'];// 收费套餐ID
                vbdT.vbd12 = vbdList[j]['vbd12'];// 诊疗收费对照数量
                vbdT.bag05 = vbdList[j]['bag05'];// 诊疗收费对照数量
                vbdT.bby05 = vbdList[j]['bby05'];// 诊疗收费对照数量
                vbd1.push(vbdT);
            }
        }

        if(!vajFlag && kucunsendFlag)
        {
            layer.alert("后台异常，请联系管理员",
                {
                    icon : 2,
                });
            $(thisbutton).removeAttr("disabled");
        }
        else if(!kucunsendFlag)
        {
            var url = rootUrl + "/clideladvice/removeAdvice";
            var data =
                {
                    "vaf01s" : failureDelVaf01s,
                    "bce03" : bce03
                };
            $.post(url, data, function(){});
        }
        else if(kucunsendFlag)
        {
            vaf01s += ")";
            vaf1 += "]";
//			var xml = "{'VAF1':" + vaf1 + ",'VBD1':" + JSON.stringify(vbd1) + "}";
            var xmlObj = {};
            xmlObj.VAF1 = vaf1;
            xmlObj.VBD1 = vbd1;
            xmlObj.zjAddList = zjAddList;
            var xml = JSON.stringify(xmlObj);
            var vaa01 = $("#vaa01").val();
            var vac01 = $("#vac01").val();
            // 开始异步发送
            $.ajax(
                {
                    async : true,
                    url : rootUrl + "/clisendadvice/clinicadvicesend",
                    data :
                        {
                            "savePrintList":JSON.stringify(savePrintList),
                            "lXml" : xml,
                            "lSign" : 2,
                            "lBCE01" : bce01,
                            "lBCE02" : "",
                            "lBCE03" : bce03,
                            "lBCK01" : bck01,
                            "lACF01" : 1,
                            "lVAA07" : vac01,
                            "lVAA01" : vaa01,
                        },
                    dataType : "json",
                    method : "post",
                    success : function(data)
                    {
                        if (data.result == "Success")
                        {
                            var t9 = new Date().getTime();
                            console.log('-------------发送医嘱总耗时：'+(t9-t1)+'毫秒---------------------------');
//					parent.savePrintList = data.list;
                            savePrintList = data.list;
//					printList = data.list;
                            // 开始更新医嘱抄送记录和生成诊疗申请单
                            var temp_vbq = {};
                            temp_vbq.vbq27 = $(".e_jianchamudi").val();
                            temp_vbq.vbq28 = $(".e_linchuangzhenduan").val();
                            temp_vbq.vbq29 = $(".e_binglizhaiyao").val();
                            temp_vbq.vbq30 = $(".e_fuzhujiancha").val();
                            var url9 = rootUrl + "/clidoctor/nurse_Lis_Bills_Print_batch";
                            var params9 = {};
                            params9.bce03 = bce03;
                            params9.cbm01Arr = JSON.stringify(cbm01Arr);
                            params9.vbq1 = JSON.stringify(temp_vbq);
                            $.ajax(
                                {
                                    url : url9,
                                    type : 'post',
                                    dataType : 'json',
                                    data : params9,
                                    success : function(data9)
                                    {
                                        $(thisbutton).removeAttr("disabled");
                                        var t2 = new Date().getTime();
                                        console.log('-------------发送医嘱总耗时：'+(t2-t9)+'毫秒---------------------------');
                                        layer.msg('发送成功',
                                            {
                                                time : 3000,
                                                icon : 1,
                                                skin : 'layui-layer-msg1'
                                            });
                                        // 如果是一卡通扣费用户，执行扣费操作
                                        var vipId = $("#vipId").text();
                                        if(false)
//						if (valueArr['p_9999_9999_112']=='1' && vipId != "--")
                                        {
                                            var msg = "";
                                            if ($("#vbu14").text() * 1 < totalVbi)
                                            {
                                                msg = "卡内基本余额：" + $("#vbu14").text() + "；本次消费总额：" + totalVbi + "。请先充值。。。";
                                                layer.alert(msg,
                                                    {
                                                        icon : 1,
                                                        title : "温馨提示："
                                                    });
                                                return true;
                                            }
                                            else
                                            {
                                                // msg =
                                                // "卡内基本余额："+$("#vbu14").text()+"；本次消费总额："+totalVbi+"。";
                                                // layer.alert(msg, {icon:1,title:"温馨提示："});
                                                vbu09 = newCardOut(2);// 弹出消费窗口
                                                vajList = data.rows;
                                            }

                                        }
                                        else
                                        {
                                            // 勾选直接打印调用
                                            var flag = $("#send_is_print").parent().attr("class").indexOf("checked")>=0;
                                            //判断是否关闭新开界面
                                            debugger;
                                            var flag_url = getUrlParam("yiyuanId");
                                            var lvac01 = $("#vac01").val();
                                            if(valueArr['p_100_105002_402']=="0"||flag_url)
                                            {
                                                if(data.commList&&data.commList.length>0){
                                                    tipCardMsg(data.commList);
                                                }
                                                printIm(flag,savePrintList);
                                                parent.reloadPatientInfo(lvac01);
                                                layer.close(zhenjin_index);
                                                $(thisbutton).removeAttr("disabled");
                                                loadEmrInit();
                                                isInfectionsDisease(getDiagnoseSql()); //传染病报告卡
                                            }
                                            else
                                            {
                                                debugger
                                                var sobj = {};
                                                sobj.vac01 = lvac01;
                                                sobj.flag = flag;
                                                sobj.list = savePrintList;
                                                sobj.sql = getDiagnoseSql();
                                                if(data.commList&&data.commList.length>0){
                                                    sobj.msg = feeTipMsg(data.commList);
                                                    parent.closeAndPrint(sobj);

                                                }else{
                                                    sobj.msg = false;
                                                    parent.closeAndPrint(sobj);
                                                }
                                            }
//							$("#sendAdvice_btn").trigger("click");
                                        }
//						var selectNameMz = getUrlParam("selectNameMz");
//						if(selectNameMz){
//							sendMsgToShoushu(selectNameMz);
//						}
                                    }
                                });
                        }
                        else
                        {
                            layer.alert(data.resultMsg,
                                {
                                    icon : 2,
                                });
                            $(thisbutton).removeAttr("disabled");
                        }
                    }
                });
        }
    }
}
//诊断
function getDiagnoseSql(){
    debugger;
    var sql = "(",arr = [];
    var allDia = $("#tagsinput_item .bootstrap-tagsinput").find(".label-info"); //诊断
    allDia.each(function(i,e){
        var str = $(e).attr("data-info");
        if(str){
            var sobj = JSON.parse(str);
            if(sobj.bak01a){
                arr.push(sobj.bak01a);
            }
        }
    })
    if(arr.length<1){
        arr.push(-1);
    }
    sql += arr.join(",");
    sql += ")";
    return sql;
}
function send_print(id, cbm01)
{
    var url = printUrl + "/printtoolrest/printToPdf/" + id + "?cbm01=" + cbm01;
    layer.open(
        {
            type : 2,
            title : false, // title 不显示
            closeBtn : 0, // 不显示 layer 弹框关闭按钮
            shadeClose : false,
            shade : false,
            area : [
                '0%', '0%'
            ], // 在页面上不显示
            content : url, // iframe的url,
            success : function()
            {

            },
            error:function(a,b,c)
            {
                layer.msg(c, {icon: 2,time:2000,skin: 'layui-layer-msg2'});
            }
        });
}

/**
 * 点击额确认交易的事件
 */
function chareCardUpdate2()
{
    var vipId = $("#vipId").text();
    $.ajax(
        {
            url : rootUrl + "/clidoctor/getMD5PassWord",
            type : "GET",
            dataType : 'json',
            data :
                {
                    password : vbu09
                },
            success : function(json)
            {
                if (cardMap.vbu09 != json.pass)
                {
                    layer.alert("密码错误，请重新输入");
                }
                else if (cardMap.vbu09 == json.pass)
                {
                    layer.closeAll();
                    for (var int = 0; int < vajList.length; int++)
                    {
                        var vaj = vajList[int];
                        var params = {};
                        params.VAA01 = vaj.vaa01;
                        params.VAA07 = vaj.vaa07;
                        params.VAI01 = vaj.vai01;
                        params.ACF01 = vaj.acf01;
                        params.BCE01 = vaj.bce03a;// 操作员id
                        params.BCK01 = vaj.bck01b;// 科室id
                        params.BCE02 = vaj.bce02b;// 操作员code
                        params.BCE02 = vaj.bce03a;// 操作员姓名
                        params.VAJ38 = vaj.vaj38;// 基本账户扣费
                        params.AType = 0;// 0 = 扣费,1 = 退费
                        params.AWorkType = 1;// 门诊记账
                        var postData = {};
                        postData.chargejson = JSON.stringify(params);
                        $.ajax(
                            {
                                url : memberUrl + "/member/memberManger/horatecardchargeupdate",// 调用rest
                                // url:"http://192.168.1.156:8089/rateweb/cloud/member/memberManger/horatecardchargeupdate",
                                type : "get",
                                dataType : "jsonp",
                                async : false,
                                data : postData,
                                success : function(data)
                                {
                                    if (data && data.result.toLowerCase() == "success")
                                    {
                                        // 调用直接打印服务
                                        printIm(data);

                                        layer.msg("会员卡 " + vipId + " 已成功扣费" + totalVbi + "元",
                                            {
                                                icon : 1,
                                                skin : 'layui-layer-msg1',
                                                time : 4000
                                            });
                                    }
                                    else
                                    {
                                        // 调用直接打印服务
                                        printIm(data);
                                        // 关闭并刷新父页面
                                        var flag_url = getUrlParam("yiyuanId");
                                        if(!flag_url){
                                            closeAndRefresh();
                                        }
                                        layer.alert("会员卡 " + vipId + " 扣费失败，请联系管理员！",
                                            {
                                                icon : 2,
                                                title : "警告"
                                            });
                                    }
                                }
                            });
                    }
                }
            }
        });
}

/**
 * 关闭并刷新parent
 */
function closeAndRefresh()
{

    var sql = getDiagnoseSql();
    var tableId = "";
    if ($(window.parent.document).find("#myPatientTab").hasClass("active"))
    {
        tableId = "myjiezhenTableList";
    }
    else
    {
        tableId = "jiezhenBenkeTable";
    }
    var rowid = $(window.parent.document).find("#" + tableId).jqGrid("getGridParam", "selrow");
    $(window.parent.document).find("#" + tableId).setSelection(rowid);
    parent.isInfectionsDisease(sql); //传染病报告卡
    parent.layer.close(parent.layer.getFrameIndex(window.name));// 关闭弹出层
}

function judgeFlag(bda01, vaf01a, vaf32)
{
    var flag = false;
    if ("128".indexOf(bda01) >= 0)
    {
        flag = true;
    }
    if ("SE".indexOf(bda01) >= 0 && vaf01a == 0)
    {
        flag = true;
    }
    if ("1238SE".indexOf(bda01) < 0 && vaf01a == 0 && vaf32 == 0)
    {
        flag = true;
    }
    return flag;
}

// 西药
function GetInfoFromTable1(tableId,vaf1, cbm1, vax1, vao1,advice_details)
{
    var tzTdindex = [
        4, 7, 8, 11, 14
    ];// 同组的数据表下标
    var zhenduanArr = [];
    $(".label-info").each(function(index, ele)
    {
        var zhenduan = $(ele).text();
        var zhenduanObj = {};
        zhenduanObj.vao15 = zhenduan;
        zhenduanArr.push(zhenduanObj);
    })
    var bck01a = bck01;
    count++;
    var rownr = 1;
    var zuValue = 0;
    $("#"+tableId+" tbody tr").each(function(i,ele)
    {
        var tdArr = $(this);
        var flag = tdArr.find(".xiyao_yznr").val().replace(/[\r\n]/g,""); // 如果医嘱内容为空，则不保存
        if (flag && flag.trim()!='')
        {
//			var str = $(ele).attr("data-info");
//			var str_obj = JSON.parse(str);

//			var bda01 = str_obj.bda01;
            var bda01 = "1";
            var zu = tdArr.find(".xiyao_zu").text();
            if (!zu) // 同组
            {
                rownr++;
                var gytjid = $(tdArr).prev().find(".xiyao_geiyao").find("select option:selected").attr("id");
                $(tdArr).find(".xiyao_geiyao").find("select option[id=" + gytjid + "]").attr('selected', true);
                var pcname = $(tdArr).prev().find(".xiyao_pinci").find("select option:selected").attr("value");
                $(tdArr).find(".xiyao_pinci").find("select").val(pcname);
                var gyzxval = $(tdArr).prev().find(".xiyao_gyzx").find("select option:selected").val();
                $(tdArr).find(".xiyao_gyzx").find("select option[value=" + gyzxval + "]").attr('selected', true);
                var yytsval = $(tdArr).prev().find(".xiyao_yyts").val().trim(); // 用药天数
                $(tdArr).find(".xiyao_yyts").val(yytsval);
                var gycsval = $(tdArr).prev().find(".xiyao_gycs").val().trim();
                $(tdArr).find(".xiyao_gycs").val(gycsval);

            }
            else
            // 非同组--组号递增
            {
                zuValue++;
            }
            if (i==0)
            {
                // vao1
                var diagnose = $(".main-header-search-input .bootstrap-tagsinput").children("span");
                var vaoLength = diagnose.length;
                for (var i = 0; i < vaoLength; i++)
                {
                    var vao1t = {};
                    var temp = $(diagnose[i]).text();
                    var str = $(diagnose[i]).attr("data-info");
                    var dobj = JSON.parse(str);
                    vao1t = $.extend(vao1t,dobj);
//					if (dobj.cam01)
//					{
//						vao1t.cam01 = dobj.cam01;
//						vao1t.bak01a = "0";// 疾病id-
//					}
//					else if (dobj.bak01)
//					{
//						vao1t.cam01 = "0";
                    vao1t.bak01a = dobj.bak01a;// 疾病id-
//					}
                    /*if (str == "-999")// 如果为手动添加的疾病
                    {
                        vao1t.cam01 = cam1Map[temp];
                    }*/
                    vao1t.vao15 = temp;
                    // vao1t.cam01 = id;
                    // vao1t.bak01a = "0";// 疾病id-
                    vao1t.cbmid = count;
                    vao1t.vaa01 = vaa01;
                    vao1t.vaa07 = vac01;
                    vao1t.acf01 = "1";
                    vao1t.vao06 = "1";// 诊断次讯
                    vao1t.vao07 = "1";// 0=初步诊断, 1=正常诊断
                    vao1t.vao10 = "0";// 0=西医, 1=中医
                    vao1t.vao11 = "1";// 1=门诊诊断, 2=入院诊断, 3=出院诊断, 4=, 5=医院感染,
                    // 6=病理诊断, 7=损伤中毒, 8=术前诊断, 9=术后诊断, 10=并发症,
                    // 11=病原学诊断，12＝尸检主要诊断
                    vao1t.vao18 = "0";// 描述: 1=疑诊, 其它正常
                    vao1t.vao22 = "1";// 描述: 0:其它地方诊断 1：医嘱单诊断 2:记账单诊断
                    vao1.push(vao1t);
                }
            }
            // cbm1
            var cbm1t = {};
            cbm1t.cbmid = count;
            cbm1t.vaa01 = vaa01;
            cbm1t.vaa07 = vac01;
            cbm1t.vap01 = 0;
            cbm1t.acf01 = 1;
            cbm1t.cbm06 = 1;// 描述: 性质: 0:不区分中、西药处方 1=西、成药, 2=中药, 3=手术记录, 4 =
            // 成药,5=卫材, 9=其他
            var cbm07 = $("#"+tableId).parents(".tab-pane").find(".tscf").val();
            cbm1t.cbm07 = cbm07;// 1=普通, 2=急诊, 3=儿童, 4=麻醉, 5=第一类精神药品, 6=第二类精神药品,
            // 7=放射药品,8=毒性药品,9=检查,10=检验,11=手术,12=治疗,99=其它
            cbm1t.bjw02 = "";// 处方分类
            cbm1t.iai03 = "";// 医疗类别编码
            cbm1t.bck01a = 0;// 病区id
            cbm1t.bck01b = bck01;// 病人科室id
            cbm1t.bck01c = $("#kaidankeshi").val();// 开单科室id
            cbm1t.cbm19 = $("#"+tableId).parents(".tab-pane").find(".zfbs").val();// 是否自费
            // var dataInfo = JSON.parse($(this).attr('data-info'));
            // cbm1t.total = dataInfo.price *
            // (tdArr.eq(9).find("input:eq(0)").val());
            cbm1.push(cbm1t);

            if (zu) // 同组
            {
                // 给药途径
                var temp1 = configData(tdArr, vaa01, vac01, count);
                temp1.lroute = "1";
                temp1.vaf11 = "2" // 长嘱还是临嘱
                temp1.vaf22 = tdArr.find(".xiyao_geiyao").find("select option:selected").text(); // 医嘱内容
                temp1.vaf32 = "1";// 正常还是给药途径
                temp1.bda01 = "T";//
                temp1.bda01a = "1";//
                temp1.rownr = "0";
                temp1.bbx01 = tdArr.find(".xiyao_geiyao").find("select option:selected").attr("id"); // 收费项目ID---
                temp1.bby01 = 0; // 收费项目ID---
                temp1.vaf18 = tdArr.find(".xiyao_dcyl").val(); // 单次用量(剂量)
                temp1.vaf20 = tdArr.find(".xiyao_dcyl").val();
                temp1.vaf26 = tdArr.find(".xiyao_pinci").find("select option:selected").text(); // 频次text
                temp1.vaf27 = tdArr.find(".xiyao_pinci").find("select option:selected").attr("id"); // 频次value
                temp1.vaf28 = 0; // 频率
                temp1.vaf29 = tdArr.find(".xiyao_pinci").find("select option:selected").val(); // 间隔单位
                temp1.vaf17 = tdArr.find(".xiyao_yyts").val(); // 用药天数
                temp1.vaf21 = tdArr.find(".xiyao_gycs").val(); // 数量
                if (!nz.test(temp1.vaf21))
                {
                    validRestult = "给药次数必须是正整数";
                    validFlg = false;
                    return false;
                }
                temp1.vaf60 = tdArr.find(".xiyao_disu").val(); // 滴速
                temp1.bck01d = tdArr.find(".xiyao_zxks").attr("id");// 执行科室ID
                temp1.bck01b = tdArr.find(".xiyao_gyzx").find("select option:selected").val();// 给药科室ID
                temp1.vaf59 = zuValue;// 组号
                temp1.vaf35 = tdArr.find(".xiyao_jinji").attr("data-value");// 紧急
                temp1.vaf58 = tdArr.find(".xiyao_zxxz").find("select option:selected").attr("id");// 执行性质
                temp1.vaf61 = tdArr.find(".xiyao_sc").val() == "" ? 0 : tdArr.find(".xiyao_sc").val();// 首次
                temp1.vaf23 = tdArr.find(".xiyao_yszt").val() ? "" : tdArr.find(".xiyao_yszt").val();// 医师嘱托
                var bce1Info = tdArr.find(".xiyao_kzys").find("option:selected");
                temp1.bce01a = bce1Info.val();// bce01a
                temp1.bce02a = bce1Info.attr("id");// bce02a
                temp1.bce03a = bce1Info.text();// bce03a
                temp1.bck01c = tdArr.find(".xiyao_kzks").find("select").val();// xiyao_kzks
                vaf1.push(temp1);
            }
            // 正常医嘱
            var temp2 = configData(tdArr, vaa01, vac01, count);
            temp2.lroute = "0";
            temp2.vaf11 = "2" // 长嘱还是临嘱
            temp2.vaf22 = tdArr.find(".xiyao_yznr").val().replace(/[\r\n]/g,""); // 医嘱内容
            temp2.vaf19 = tdArr.find(".xiyao_dcyl").val()+" "+tdArr.find(".xiyao_dcyldw").text(); // 用量
            temp2.vaf15 = tdArr.find(".xiyao_geiyao").find("select option:selected").val(); // 给药途径
            if (!temp2.vaf15)
            {
                validRestult = "西药给药途径不能为空";
                validFlg = false;
                return false;
            }

            temp2.vaf32 = "0";// 正常还是给药途径
            temp2.bda01 = bda01;//
            temp2.bda01a = "1";//
            temp2.vaf59 = zuValue;
            if (zu == "")
            {
                temp2.rownr = rownr;
            }
            else
            {
                temp2.rownr = "1";
            }
            temp2.rcurrent = "0";
            temp2.bbx01 = tdArr.find(".xiyao_yznr").next().val(); // 诊疗项目ID---
            temp2.bby01 = tdArr.find(".xiyao_yznr").next().next().val(); // 收费项目ID---
            temp2.vaf18 = tdArr.find(".xiyao_dcyl").val(); // 单次用量(剂量)
            xiyaochangdu.push(temp2.bbx01);
            // 单次用量不能为空
            if (!n.test(temp2.vaf18))
            {
                validRestult = "西药单次用量必须是数字";
                validFlg = false;
                return false;
            }
            temp2.vaf35 = tdArr.find(".xiyao_jinji").attr("data-value");// 紧急

            temp2.vaf20 = tdArr.find(".xiyao_dcyl").val().trim(); // 单次用量(剂量)

            temp2.vaf26 = tdArr.find(".xiyao_pinci").find("select option:selected").text(); // 频次
            if (!temp2.vaf26)
            {
                validRestult = "西药频次不能为空";
                validFlg = false;
                return false;
            }
            temp2.vaf27 = tdArr.find(".xiyao_pinci").find("select option:selected").attr("id"); // 给药次数
            temp2.vaf17 = tdArr.find(".xiyao_yyts").val().trim(); // 用药天数

            temp2.vaf28 = 0; //
            temp2.vaf29 = tdArr.find(".xiyao_pinci").find("select option:selected").val(); // 间隔单位
            temp2.vaf34 = 0; //
            temp2.vaf17 = tdArr.find(".xiyao_yyts").val().trim(); // 用药天数
            if (!nz.test(temp2.vaf17))
            {
                validRestult = "西药用药天数必须是正整数";
                validFlg = false;
                return false;
            }
            var jizhenTs = valueArr["p_100_105002_424"];
            if(jizhenTs!=0 && cbm07 == 2){
                if(jizhenTs<temp2.vaf17 ){
                    var jzmsg = "急诊处方限制最多开"+jizhenTs+"天的药";
                    layer.alert(jzmsg,{
                        icon : 0,
                        title : "急诊处方提示："
                    });
                    validFlg = false;
                    return false;
                }
            }

            temp2.vaf21 = tdArr.find(".xiyao_zl").val().trim(); // 数量
            if (!n.test(temp2.vaf21))
            {
                validRestult = "西药总量必须是数字";
                validFlg = false;
                return false;
            }
            temp2.vaf60 = tdArr.find(".xiyao_disu").val().trim(); // 滴速
            temp2.biw02 = tdArr.find(".xiyao_yymd").find("select option:selected").text(); // 用药目的
            temp2.bck01b = tdArr.find(".xiyao_zxks").attr("id");// 执行科室ID
            temp2.bck01d = tdArr.find(".xiyao_gyzx").find("select option:selected").val();// 给药科室默认给开嘱科室id
            if (!temp2.bck01b)
            {
                validRestult = "西药执行科室不正确";
                validFlg = false;
                return false;
            }
            temp2.vaf58 = tdArr.find(".xiyao_zxxz").find("select option:selected").attr("id");// 执行性质
            temp2.vaf61 = tdArr.find(".xiyao_sc").val() == "" ? 0 : tdArr.find(".xiyao_sc").val();// 首次
            temp2.vaf23 = tdArr.find(".xiyao_yszt").val() == "" ? "" : tdArr.find(".xiyao_yszt").val();// 医师嘱托
            temp2.vaf55 = tdArr.find(".xiyao_yzbz").val() == "" ? "" : tdArr.find(".xiyao_yzbz").val();// 医嘱备注
            temp2.vaf31 = tdArr.find(".xiyao_jjxz").find("select option:selected").val();// 计价性质
            temp2.vaf30 = tdArr.find(".xiyao_zxfa").val() == "" ? "" : tdArr.find(".xiyao_zxfa").val();// 执行方案
            var bce1Info = tdArr.find(".xiyao_kzys").find("option:selected");
            temp2.bce01a = bce1Info.val();// bce01a
            temp2.bce02a = bce1Info.attr("id");// bce02a
            temp2.bce03a = bce1Info.text();// bce03a
            temp2.veh02 = tdArr.data().veh02||"";// veh02   //医保限制用药
            temp2.bgz01 = $("#"+tableId).parents(".tab-pane").find(".xmgs").val();
            temp2.bck01c = tdArr.find(".xiyao_kzks").find("select").val();// xiyao_kzks
            vaf1.push(temp2);

            if ((valueArr['p_9999_9999_103']==1 || valueArr['p_9999_9999_103']=='1') && $("#patient_bdp02").text()!="自费")
            {
                //audit-davices
                var temp22 = {};
                temp22.lVAF06 = $("#vac01").val();
                temp22.lBBY01 = temp2.bby01;
                temp22.lVAF21 = temp2.vaf21;
                temp22.ACF01 = 1;
                temp22.BDA01 = temp2.bda01;
                temp22.lVAF22 = temp2.vaf22;
                temp22.vaf22b = 1;
                temp22.BCK01 = valueArr['p_100_105002_108'];
                temp22.lBCK03 = 'bck03';
                temp22.VAF17 = temp2.vaf17;
                temp22.VAF18 = temp2.vaf18;
                temp22.VAF26 = temp2.vaf26;
                temp22.VAF27 = temp2.vaf27;
                temp22.VAF28 = temp2.vaf28;
                temp22.vaj23 = 1;
                temp22.vaj26 = 1;
                temp22.vaj27 = 1;
                temp22.VAF29 = temp2.vaf29?temp2.vaf29:"1";
                temp22.VAF58 = temp2.vaf58;
                temp22.Compound = 1;

                var take_frequence = tdArr.find(".xiyao_pinci").find("select option:selected").attr("data-bdi03");
                $.ajax(
                    {
                        url : rootUrl + "/doctoradviceeditor/querymedicineadvicefeedetail",
                        type : "post",
                        dataType : "json",
                        data : temp22,
                        async : false,
                        success : function(data)
                        {
                            if (data && data.list && data.list.length>0)
                            {
                                var advice = data.list[0];
                                var advice_detail_obj =
                                    {
                                        'project_code' : advice.iah04,
                                        'hospital_code' : advice.bby01,
                                        'project_name' : advice.bby05,
                                        'standard_code' : '',
                                        'is_out_recip' : 0,
                                        'recipe_no' : hccode+count,
                                        'invoice_project' : '',
                                        'dose_form' : '',
                                        'medical_specification' : '',
                                        'price' : advice.bby25,
                                        'medical_number' : advice.vaf21,
                                        'dose_unit' : advice.bby08,
                                        'amount' : advice.price,
                                        //								'self_pay_rate':'',
                                        'use_day' : advice.vaf17,
                                        'single_dose_number' : advice.vaf18,
                                        'single_dose_unit' : advice.bdg02,
                                        'take_medical_number' : advice.vaf18,
                                        'take_medical_unit' : advice.bdg02,
                                        'dose_day' : advice.vaf17,
                                        'deliver_way' : '',
                                        'take_frequence' : take_frequence?take_frequence:"OTH.P",
                                        'location_code' : '',
                                        'location_name' : ''
                                    }
                                advice_details.push(advice_detail_obj);
                            }
                        }
                    });
            }
        }
    });
}
//中药表格数据按顺序组装
function configDataOrder(tableId){
    var zhongyaoArr=[];
    var table1 = $(tableId).find(".china_medicine_tbody1 tr");
    var table2 = $(tableId).find(".china_medicine_tbody2 tr");
    var t2 = 0;
    table1.each(function(index,ele){
        var flag = $(this).find(".zhongyao_yznr").val().replace(/[\r\n]/g,""); // 根据医嘱内容判断是否保存
        if (flag && flag.trim()!='')
        {
            zhongyaoArr.push(ele);
        }
        var tr2 = table2[index];
        if(tr2){
            var flag1 = $(tr2).find(".zhongyao_yznr").val().replace(/[\r\n]/g,""); // 根据医嘱内容判断是否保存
            if (flag1 && flag1.trim()!='')
            {
                zhongyaoArr.push(tr2);
            }

        }
        t2 = index+1;
    })
    for(var i= t2;i<table2.length;i++){
        var flag = $(table2[i]).find(".zhongyao_yznr").val().replace(/[\r\n]/g,""); // 根据医嘱内容判断是否保存
        if (flag && flag.trim()!='')
        {
            zhongyaoArr.push(table2[i]);
        }
    }
    return zhongyaoArr;
}
// 中药
function GetInfoFromTable3(tableId,vaf1, cbm1, vax1, vao1,advice_details)
{
    var bck01a = bck01;
//	var count = 20;
    var tableObj = document.getElementById("");
    var temp1;
    count++;
    var rownr = 0;
    var temp33 = [];
    var zhongyaoArr = configDataOrder(tableId);
//	var zhongyaoArr=[];
//	debugger;
////	$("#"+tableId+" tr").each(function(index,ele){
//	$(tableId).find("tbody tr").each(function(index,ele){
//		var flag = $(this).find(".zhongyao_yznr").val().replace(/[\r\n]/g,""); // 根据医嘱内容判断是否保存
//		if (flag && flag.trim()!='')
//		{
//			zhongyaoArr.push(ele)
//		}
//	})
    for(var i =0;i<zhongyaoArr.length;i++)
    {
        var tdArr = $(zhongyaoArr[i]);
//				var flag = tdArr.find(".zhongyao_yznr").val(); // 根据医嘱内容判断是否保存
//				if (flag)
//				{
        zhongyaochangdu++;
        var zu = 1;
        if (i == 0)
        {
            // 医嘱类别
            // vao1
            var diagnose = $(".main-header-search-input .bootstrap-tagsinput").children("span");
            var vaoLength = diagnose.length;
            for (var j = 0; j < vaoLength; j++)
            {
                var vao1t = {};
                var temp = $(diagnose[j]).text();
                var str = $(diagnose[i]).attr("data-info");
                var dobj = JSON.parse(str);
                vao1t = $.extend(vao1t,dobj);
//							if (dobj.cam01)
//							{
//								vao1t.cam01 = dobj.cam01;
//								vao1t.bak01a = "0";// 疾病id-
//							}
//							else if (dobj.bak01)
//							{
//								vao1t.cam01 = "0";
//								vao1t.bak01a = dobj.bak01;// 疾病id-
//							}
                if (str == -999)// 如果为手动添加的疾病
                {
                    vao1t.cam01 = cam1Map[temp];
                }
                vao1t.vao15 = temp;
                // vao1t.cam01 = id;
                vao1t.cbmid = count;
                vao1t.vaa01 = vaa01;
                vao1t.vaa07 = vac01;
                vao1t.acf01 = "1";
                vao1t.vao06 = "1";// 诊断次讯
                vao1t.vao07 = "1";// 0=初步诊断, 1=正常诊断
                vao1t.vao10 = "0";// 0=西医, 1=中医
                vao1t.vao11 = "1";// 1=门诊诊断, 2=入院诊断, 3=出院诊断, 4=,
                // 5=医院感染, 6=病理诊断, 7=损伤中毒,
                // 8=术前诊断, 9=术后诊断, 10=并发症,
                // 11=病原学诊断，12＝尸检主要诊断
                // vao1t.bak01a = "0";// 疾病id-
                vao1t.vao18 = "0";// 描述: 1=疑诊, 其它正常
                vao1t.vao22 = "1";// 描述: 0:其它地方诊断 1：医嘱单诊断 2:记账单诊断
                vao1.push(vao1t);

            }
            // cbm1
            var cbm1t = {};
            cbm1t.cbmid = count;
            cbm1t.vaa01 = vaa01;
            cbm1t.vaa07 = vac01;
            cbm1t.vap01 = 0;
            cbm1t.acf01 = 1;
            cbm1t.cbm06 = 2;// 描述: 性质: 0:不区分中、西药处方 1=西、成药, 2=中药,
            // 3=手术记录, 4 = 成药,5=卫材, 9=其他
            var cbm07 = $(tableId).parents(".tab-pane").find(".tscf").val();
            cbm1t.cbm07 = cbm07;// 1=普通, 2=急诊, 3=儿童, 4=麻醉, 5=第一类精神药品, 6=第二类精神药品,
            // 7=放射药品,8=毒性药品,9=检查,10=检验,11=手术,12=治疗,99=其它
            cbm1t.bjw02 = "";// 处方分类
            cbm1t.iai03 = "";// 医疗类别编码
            cbm1t.bck01a = 0;// 病区id
            cbm1t.bck01b = bck01;// 病人科室id
            cbm1t.bck01c = $("#kaidankeshi").val();// 开单科室id
            cbm1t.cbm19 = $(tableId).parents(".tab-pane").find(".zfbs").val();// 状态
            // var dataInfo = JSON.parse($(this).attr('data-info'));
            // cbm1t.total = (dataInfo.price) *
            // (tdArr.eq(9).find("input:eq(0)").val());//单价隐藏
            cbm1.push(cbm1t);

            var zhongyaoCom =$(tableId).parents(".china_medicine").find(".china_medicine_com");
            // 方剂
            temp1 = configData(tdArr, vaa01, vac01, count);
            temp1.cbmid = count;
            temp1.lroute = "0";
            temp1.vaf11 = "2" // 长嘱还是临嘱
            temp1.vaf15 = $(zhongyaoCom).find(".zhongyao_zyyf").find("select option:selected").text(); // 中药用法
            temp1.vaf26 = $(zhongyaoCom).find(".zhongyao_pc").find("select option:selected").text(); // 频次
            temp1.vaf17 = 0;
            temp1.vaf18 = 0;
            temp1.vaf20 = 0;
            temp1.vaf27 = 0;
            temp1.vaf28 = 0; //
            temp1.vaf34 = 0; //
            temp1.vaf21 = $(zhongyaoCom).find(".zhongyao_js").val().trim();// 剂数
            temp1.vaf32 = "1";// 正常还是给药途径
            temp1.bda01 = "8";//
            temp1.bda01a = "8";//
            temp1.rownr = rownr;
            temp1.bbx01 = $(zhongyaoCom).find(".zhongyao_zyyf").find("select option:selected").val(); // 用药用法的bbx01
            temp1.bby01 = 0; // 收费项目ID---
            temp1.biw02 = $(zhongyaoCom).find(".zhongyao_yymd").find("select option:selected").text();// 用药目的
            temp1.bck01b =$(zhongyaoCom).find(".zhongyao_zxks select").val();// 执行科室ID
            temp1.bck01d =$(zhongyaoCom).find(".zhongyao_gyzx select").val();// 给药科室默认开嘱科室id
            temp1.vaf58 = $(zhongyaoCom).find(".zhongyao_zxxz").find("select option:selected").attr("id");// 执行性质
            temp1.vaf59 = zu;// 组号
            temp1.vaf61 = 0;// 首次
            temp1.vaf23 =  $(zhongyaoCom).find(".zhongyao_yszt").val();//医生嘱托
            temp1.vaf55 = $(zhongyaoCom).find(".zhongyao_yzbz").val();// 医嘱备注
            /********中药脚注赋值 jiaozhuText*******/
            var jiaozhuVal = tdArr.find(".zhongyao_jz").find("select").val();
            var jiaozhuText;
            if(jiaozhuVal == "-1"){
                jiaozhuText="";
            }else{
                jiaozhuText = tdArr.find(".zhongyao_jz").find("select option:selected").text();
            }

            var adviceContent = tdArr.find(".zhongyao_yznr").val().replace(/[\r\n]/g,"") + tdArr.find(".zhongyao_dl").val()+tdArr.find(".zhongyao_dw").text() + " " + jiaozhuText+ ";";
            var jianfa = $(zhongyaoCom).find(".zhongyao_jf").find("select option:selected").text();// 煎法
            temp1.vaf22 = "中药"+temp1.vaf21+"付，" + temp1.vaf26 + "，" + temp1.vaf15 + "，" + jianfa + "：" + adviceContent; // 医嘱内容
            temp1.vaf36 = tdArr.find(".layer-date").val(); // 开始时间
            temp1.vaf55 = $(zhongyaoCom).find(".zhongyao_yzbz").val();// 医嘱备注
            temp1.vaf31 = $(zhongyaoCom).find(".zhongyao_jjxz").find("select option:selected").val();// 计价性质;
            temp1.vaf30 = $(zhongyaoCom).find(".zhongyao_zxfa").val();// 执行方案
            var bce1Info = $(zhongyaoCom).find(".zhongyao_kzys").find("option:selected");
            temp1.bce01a = bce1Info.val();// bce01a
            temp1.bce02a = bce1Info.attr("id");// bce02a
            temp1.bce03a = bce1Info.text();// bce03a
            temp1.bck01c = $(zhongyaoCom).find(".zhongyao_kzks").find("select").val();// zhongyao_kzks

        }
        var adviceContent;
        if (i > 0)
        {
            var jiaozhuVal = tdArr.find(".zhongyao_jz").find("select").val();
            var jiaozhuText;
            if(jiaozhuVal == "-1"){
                jiaozhuText="";
            }else{
                jiaozhuText = tdArr.find(".zhongyao_jz").find("select option:selected").text();
            }
            adviceContent = tdArr.find(".zhongyao_yznr").val().replace(/[\r\n]/g,"") + tdArr.find(".zhongyao_dl").val()+tdArr.find(".zhongyao_dw").text()+" " + jiaozhuText + ";";
            // + tdArr.eq(8).find("select
            // option:selected").text()+";";
            temp1.vaf22 = temp1.vaf22 + " " + adviceContent; // 医嘱内容
        }
        // 中药
        rownr++;
        var temp2 = configData(tdArr, vaa01, vac01, count);
        temp2.cbmid = count;
        temp2.lroute = "0";
        temp2.vaf11 = "2" // 长嘱还是临嘱
        temp2.vaf14 = "";// 标本部位
        temp2.vaf15 = $(zhongyaoCom).find(".zhongyao_zyyf").find("select option:selected").text(); // 中药用法
        if (!temp2.vaf15)
        {
            validRestult = "请选择中药用法";
            validFlg = false;
            return false;
        }
        temp2.vaf26 = $(zhongyaoCom).find(".zhongyao_pc").find("select option:selected").text(); // 频次
        temp2.vaf17 = 0;
        temp2.vaf18 = 0;
        temp2.vaf19 = tdArr.find(".zhongyao_dl").val().trim();
//					var vaf191 = tdArr.find(".zhongyao_dl").val().trim();
        temp2.vaf20 = tdArr.find(".zhongyao_zl").val();
        if (!n.test(temp2.vaf19))
        {
            validRestult = "中药单量必须是数字";
            validFlg = false;
            return false;
        }
        temp2.vaf27 = 0;
        temp2.vaf28 = 0; //
        temp2.vaf34 = 0; //
        temp2.vaf21 = $(zhongyaoCom).find(".zhongyao_js").val().trim();// 剂数
        if (!n.test(temp2.vaf21))
        {
            validRestult = "中药剂数必须是数字";
            validFlg = false;
            return false;
        }

        temp2.vaf22 = tdArr.find(".zhongyao_yznr").val().replace(/[\r\n]/g,""); // 医嘱内容
        var jiaozhuVal = tdArr.find(".zhongyao_jz").find("select").val();
        var jiaozhuText;
        if(jiaozhuVal == "-1"){
            jiaozhuText="";
        }else{
            jiaozhuText = tdArr.find(".zhongyao_jz").find("select option:selected").text();
        }

        temp2.vaf23 = jiaozhuText; // 脚注
        temp2.vaf31 = $(zhongyaoCom).find(".zhongyao_jjxz").find("select option:selected").val();// 计价性质;
        temp2.vaf32 = "0";// 正常还是给药途径
        temp2.bda01 = "3";//
        temp2.bda01a = "8";//
        temp2.rownr = rownr;
        temp2.rcurrent = "0";
        temp2.biw02 = ""; // 用药目的
        temp2.bbx01 = tdArr.find(".zhongyao_yznr").next().val();// 诊疗项目ID---
        temp2.bby01 = tdArr.find(".zhongyao_yznr").next().next().val(); // 收费项目ID---
        temp2.bck01b = $(zhongyaoCom).find(".zhongyao_zxks select").val();// 执行科室ID
        temp2.bck01d = bck01;// 给药科室默认开嘱科室id
        temp2.vaf58 = $(zhongyaoCom).find(".zhongyao_zxxz").find("select option:selected").attr("id");// 执行性质
        temp2.vaf59 = zu;// 组号
        temp2.vaf61 = 0;// 首次
        temp2.vaf36 = tdArr.find(".layer-date").val(); // 开始时间
        var bce1Info = $(zhongyaoCom).find(".zhongyao_kzys").find("option:selected");
        temp2.bce01a = bce1Info.val();// bce01a
        temp2.bce02a = bce1Info.attr("id");// bce02a
        temp2.bce03a = bce1Info.text();// bce03a
        temp2.veh02 = tdArr.data().veh02||"";// veh02   //医保限制用药
        temp2.bck01c = $(zhongyaoCom).find(".zhongyao_kzks").find("select").val();// zhongyao_kzks
        temp33.push(temp2);
        if ((valueArr['p_9999_9999_103']==1 || valueArr['p_9999_9999_103']=='1') && $("#patient_bdp02").text()!="自费")
        {
            //audit-davices
            var temp22 = {};
            temp22.lVAF06 = $("#vac01").val();
            temp22.lBBY01 = temp2.bby01;
            temp22.lVAF21 = temp2.vaf21;
            temp22.ACF01 = 1;
            temp22.BDA01 = temp2.bda01;
            temp22.lVAF22 = temp2.vaf22;
            temp22.vaf22b = 1;
            temp22.BCK01 = valueArr['p_100_105002_108'];
            temp22.lBCK03 = 'bck03';
            temp22.VAF17 = temp2.vaf17;
            temp22.VAF18 = temp2.vaf18;
            temp22.VAF26 = temp2.vaf26;
            temp22.VAF27 = temp2.vaf27;
            temp22.VAF28 = temp2.vaf28;
            temp22.vaj23 = 1;
            temp22.vaj26 = 1;
            temp22.vaj27 = 1;
            temp22.VAF29 = temp2.vaf29?temp2.vaf29:"1";
            temp22.VAF58 = temp2.vaf58;
            temp22.Compound = 1;
            var take_frequence = $(zhongyaoCom).find(".zhongyao_pc").find("select option:selected").attr("data-bdi03");
            $.ajax(
                {
                    url : rootUrl + "/doctoradviceeditor/querymedicineadvicefeedetail",
                    type : "post",
                    dataType : "json",
                    data : temp22,
                    async : false,
                    success : function(data)
                    {
                        if (data && data.list && data.list.length>0)
                        {
                            var advice = data.list[0];
                            var advice_detail_obj =
                                {
                                    'project_code' : advice.iah04,
                                    'hospital_code' : advice.bby01,
                                    'project_name' : advice.bby05,
                                    'standard_code' : '',
                                    'is_out_recip' : 0,
                                    'recipe_no' : hccode+count,
                                    'invoice_project' : '',
                                    'dose_form' : '',
                                    'medical_specification' : '',
                                    'price' : advice.bby25,
                                    'medical_number' : advice.vaf21,
                                    'dose_unit' : advice.bby08,
                                    'amount' : advice.price,
                                    //								'self_pay_rate':'',
                                    'use_day' : advice.vaf17,
                                    'single_dose_number' : advice.vaf18,
                                    'single_dose_unit' : advice.bdg02,
                                    'take_medical_number' : advice.vaf18,
                                    'take_medical_unit' : advice.bdg02,
                                    'dose_day' : advice.vaf17,
                                    'deliver_way' : '',
                                    'take_frequence' : take_frequence?take_frequence:"OTH.P",
                                    'location_code' : '',
                                    'location_name' : ''
                                }
                            advice_details.push(advice_detail_obj);
                        }
                    }
                });
        }
        if (i == zhongyaoArr.length - 1)
        {
            temp1.vaf22 = temp1.vaf22.substr(0, temp1.vaf22.length - 1);
            vaf1.push(temp1);
            rownr++;
            for (var k = 0; k < temp33.length; k++)
            {
                vaf1.push(temp33[k]);
            }
            // 煎法
            var temp3 = configData(tdArr, vaa01, vac01, count);
            temp3.cbmid = count;
            temp3.lroute = "0";
            temp3.vaf11 = "2" // 长嘱还是临嘱
            temp3.vaf14 = "";// 标本部位
            temp3.vaf26 = $(zhongyaoCom).find(".zhongyao_pc").find("select option:selected").text(); // 频次
            temp3.vaf17 = 0;
            temp3.vaf18 = 0;
            temp3.vaf20 =$(zhongyaoCom).find(".zhongyao_gycs").val();// 给药次数
            if (!nz.test(temp3.vaf20))
            {
                validRestult = "给药次数必须是正整数";
                validFlg = false;
                return false;
            }
            temp3.vaf27 = 0;
            temp3.vaf28 = 0; //
            temp3.vaf34 = 0; //
            temp3.vaf21 = $(zhongyaoCom).find(".zhongyao_jc").val();// 煎次
            temp3.vaf22 = $(zhongyaoCom).find(".zhongyao_jf").find("select option:selected").text();// 用法
            temp3.vaf23 = 'jianfa';
            temp3.vaf32 = "0";// 正常还是给药途径
            temp3.bbx01 = $(zhongyaoCom).find(".zhongyao_jf").find("select option:selected").val(); // 用法的bbx01
            temp3.bby01 = 0;
            temp3.bda01 = "T";//
            temp3.bda01a = "8";//
            temp3.rownr = rownr;
            temp3.rcurrent = "0";
            temp3.biw02 = ""; // 用药目的
            temp3.bck01b = $(zhongyaoCom).find(".zhongyao_gyzx select").val();
            temp3.bck01d = $(zhongyaoCom).find(".zhongyao_gyzx select").val();
            temp3.vaf58 = $(zhongyaoCom).find(".zhongyao_zxxz").find("select option:selected").attr("id");// 执行性质
            temp3.vaf59 = zu;// 组号
            temp3.vaf61 = 0;// 首次
            temp3.vaf36 = tdArr.find(".layer-date").val(); // 开始时间
            var bce1Info = $(zhongyaoCom).find(".zhongyao_kzys").find("option:selected");
            temp3.bce01a = bce1Info.val();// bce01a
            temp3.bce02a = bce1Info.attr("id");// bce02a
            temp3.bce03a = bce1Info.text();// bce03a
//						temp3.vaf23 =  $(zhongyaoCom).find(".zhongyao_yszt").val();//医生嘱托
            temp3.vaf55 = $(zhongyaoCom).find(".zhongyao_yzbz").val();// 医嘱备注
            temp3.vaf31 = $(zhongyaoCom).find(".zhongyao_jjxz").find("select option:selected").val();// 计价性质;
            temp3.bck01c = $(zhongyaoCom).find(".zhongyao_kzks").find("select").val();// zhongyao_kzks
            vaf1.push(temp3);
        }
//				}
    }
//			});
}
// 检验
function GetInfoFromTableL(tableId,vaf1, cbm1, vax1, vao1,advice_details)
{
    var bck01a = bck01;
//	var count = 40;
    count++;
    var zuValue = 0;
    $("#"+tableId+" tbody tr").each(function(i)
    {
        var tdArr = $(this);
        var flag = tdArr.find(".jianyan_yznr").val().replace(/[\r\n]/g,""); // 医嘱内容
        if (flag && flag.trim()!='')
        {
            // 医嘱类别
            var bad01 = "L";
            var zu = tdArr.find(".jianyan_zu").text();
            if (zu != "") // 非同组
            {
                zuValue++;
            }
            if (i==0)
            {
                // vao1
                var diagnose = $(".main-header-search-input .bootstrap-tagsinput").children("span");
                var vaoLength =diagnose.length;
                for (var i = 0; i < vaoLength; i++)
                {
                    var vao1t = {};
                    var temp = $(diagnose[i]).text();
                    var str = $(diagnose[i]).attr("data-info");
                    var dobj = JSON.parse(str);
                    vao1t = $.extend(vao1t,dobj);
//					if (dobj.cam01)
//					{
//						vao1t.cam01 = dobj.cam01;
//						vao1t.bak01a = "0";// 疾病id-
//					}
//					else if (dobj.bak01)
//					{
//						vao1t.cam01 = "0";
//						vao1t.bak01a = dobj.bak01;// 疾病id-
//					}
                    if (str == -999)// 如果为手动添加的疾病
                    {
                        vao1t.cam01 = cam1Map[temp];
                    }
                    vao1t.vao15 = temp;
                    // vao1t.cam01 = id;
                    vao1t.cbmid = count;
                    vao1t.vaa01 = vaa01;
                    vao1t.vaa07 = vac01;
                    vao1t.acf01 = "1";
                    vao1t.vao06 = "1";// 诊断次讯
                    vao1t.vao07 = "1";// 0=初步诊断, 1=正常诊断
                    vao1t.vao10 = "0";// 0=西医, 1=中医
                    vao1t.vao11 = "1";// 1=门诊诊断, 2=入院诊断, 3=出院诊断, 4=, 5=医院感染,
                    // 6=病理诊断, 7=损伤中毒, 8=术前诊断, 9=术后诊断, 10=并发症,
                    // 11=病原学诊断，12＝尸检主要诊断
                    // vao1t.bak01a = "0";// 疾病id-
                    vao1t.vao18 = "0";// 描述: 1=疑诊, 其它正常
                    vao1t.vao22 = "1";// 描述: 0:其它地方诊断 1：医嘱单诊断 2:记账单诊断
                    vao1.push(vao1t);
                }
            }
            // cbm1
            var cbm1t = {};
            cbm1t.cbmid = count;
            cbm1t.vaa01 = vaa01;
            cbm1t.vaa07 = vac01;
            cbm1t.vap01 = 0;
            cbm1t.acf01 = 1;
            cbm1t.cbm06 = 9;// 描述: 性质: 0:不区分中、西药处方 1=西、成药, 2=中药, 3=手术记录, 4 =
            // 成药,5=卫材, 9=其他
            var cbm07 = $("#"+tableId).parents(".tab-pane").find(".tscf").val();
            cbm1t.cbm07 = cbm07;// 1=普通, 2=急诊, 3=儿童, 4=麻醉, 5=第一类精神药品, 6=第二类精神药品,
            // 7=放射药品,8=毒性药品,9=检查,10=检验,11=手术,12=治疗,99=其它
            cbm1t.bjw02 = "";// 处方分类
            cbm1t.iai03 = "";// 医疗类别编码
            cbm1t.bck01a = 0;// 病区id
            cbm1t.bck01b = bck01;// 病人科室id
            cbm1t.bck01c = $("#kaidankeshi").val();// 开单科室id
            cbm1t.cbm19 = $("#"+tableId).parents(".tab-pane").find(".zfbs").val();// 状态
            // var dataInfo = JSON.parse($(this).attr('data-info'));
            // cbm1t.total = (dataInfo.price) *
            // (tdArr.eq(9).find("input:eq(0)").val());
            cbm1.push(cbm1t);
            // 检验
            var temp1 = configData(tdArr, vaa01, vac01, count);
            temp1.lroute = "0";
            temp1.vaf11 = "2" // 长嘱还是临嘱
            temp1.vaf14 = tdArr.find(".jianyan_yblx").find("select option:selected").text();// 样本
            if (!temp1.vaf14)
            {
                validRestult = "请填写检验的样本类型";
                validFlg = false;
                return false;
            }

            temp1.vaf22 = tdArr.find(".jianyan_yznr").val().replace(/[\r\n]/g,""); // 医嘱内容
            temp1.vaf32 = "0";// 正常还是给药途径
            temp1.bda01 = bad01;//
            temp1.bda01a = bad01;//
            temp1.rownr = "0";
            temp1.rcurrent = "0";
            temp1.biw02 = ""; // 用药目的
            temp1.bbx01 = tdArr.find(".jianyan_yznr").next().val(); // 诊疗项目ID---
            temp1.bby01 = 0; // 收费项目ID---
            temp1.vaf17 = 0; // 用药天数
            temp1.vaf28 = 0; //
            temp1.vaf18 = 0; //
            temp1.vaf20 = 0; //
            temp1.vaf34 = 0; //
            temp1.vaf21 = tdArr.find(".jianyan_zl").val().trim(); // 数量
            if (!n.test(temp1.vaf21))
            {
                validRestult = "检验总量必须为数字";
                validFlg = false;
                return false;
            }
            temp1.bck01b = tdArr.find(".jianyan_zxks").find("select option:selected").val();// 执行科室ID
            temp1.vaf58 = tdArr.find(".jianyan_zxxz").find("select option:selected").attr("id");// 执行性质
            temp1.vaf61 = 0;// 首次
            temp1.vaf59 = zu;
            temp1.vaf35 = tdArr.find(".jianyan_jinji").attr("data-value");// 紧急
            temp1.vaf23 = tdArr.find(".jianyan_yszt").val() == "" ? "" : tdArr.find(".jianyan_yszt").val();// 医师嘱托
            temp1.vaf55 = tdArr.find(".jianyan_yzbz").val() == "" ? "" : tdArr.find(".jianyan_yzbz").val();// 医嘱备注
            temp1.vaf31 = tdArr.find(".jianyan_jjxz").find("select option:selected").val();// 计价性质
            temp1.vaf30 = tdArr.find(".jianyan_zxfa").val() == "" ? "" : tdArr.find(".jianyan_zxfa").val();// 执行方案
            var bce1Info = tdArr.find(".jianyan_kzys").find("option:selected");
            temp1.bce01a = bce1Info.val();// bce01a
            temp1.bce02a = bce1Info.attr("id");// bce02a
            temp1.bce03a = bce1Info.text();// bce03a
            temp1.bck01c = tdArr.find(".jianyan_kzks").find("select").val();// jianyan_kzks
            vaf1.push(temp1);

            if ((valueArr['p_9999_9999_103']==1 || valueArr['p_9999_9999_103']=='1') && $("#patient_bdp02").text()!="自费")
            {
                //audit-davices
                var temp22 = {};
                temp22.lVAF06 = $("#vac01").val();
                temp22.lBBY01 = temp1.bby01;
                temp22.lBBX01 = temp1.bbx01;
                temp22.lVAF21 = temp1.vaf21;
                temp22.ACF01 = 1;
                temp22.BDA01 = temp1.bda01;
                temp22.lVAF22 = temp1.vaf22;
                temp22.vaf22b = 1;
                temp22.BCK01 = valueArr['p_100_105002_108'];
                temp22.lBCK03 = 'bck03';
                temp22.lBCK03F = 'bck03f';
                temp22.VAF17 = temp1.vaf17;
                temp22.VAF18 = "1";
                temp22.VAF26 = tdArr.find(".jianyan_pc").text();
                temp22.VAF27 = "1";
                temp22.VAF28 = temp1.vaf28;
                temp22.vaj23 = 1;
                temp22.vaj26 = 1;
                temp22.vaj27 = 1;
                temp22.VAF29 = '1';
                temp22.VAF58 = temp1.vaf58;
                temp22.Compound = 1;
                var take_frequence = tdArr.find(".jianyan_pc").find("select option:selected").attr("data-bdi03");
                $.ajax(
                    {
                        url : rootUrl + "/doctoradviceeditor/queryfeedetail",
                        type : "post",
                        dataType : "json",
                        data : temp22,
                        async : false,
                        success : function(data)
                        {
                            if (data && data.list && data.list.length>0)
                            {
                                for (var int = 0; int < data.list.length; int++)
                                {
                                    var advice = data.list[int];
                                    var advice_detail_obj =
                                        {
                                            'project_code' : advice.iah04,
                                            'hospital_code' : advice.bby01,
                                            'project_name' : advice.bby05,
                                            'standard_code' : '',
                                            'is_out_recip' : 0,
                                            'recipe_no' : hccode+count,
                                            'invoice_project' : '',
                                            'dose_form' : '',
                                            'medical_specification' : '',
                                            'price' : advice.bby25,
                                            'medical_number' : advice.vaf21,
                                            'dose_unit' : "",
                                            'amount' : advice.bby25,
                                            'use_day' : "",
                                            'single_dose_number' : "",
                                            'single_dose_unit' : "",
                                            'take_medical_number' : "",
                                            'take_medical_unit' : "",
                                            'dose_day' : "",
                                            'deliver_way' : '',
                                            'take_frequence' : take_frequence?take_frequence:"OTH.P",
                                            'location_code' : '',
                                            'location_name' : ''
                                        }

                                    advice_details.push(advice_detail_obj);
                                }
                            }
                        }
                    });
            }
        }
    });
}

// 检查
function GetInfoFromTableE(tableId,vaf1, cbm1, vax1, vao1, vbq1,advice_details)
{
    var bck01a = bck01;
//	var count = 60;
    count++;
    var zuValue = 0;
    /*
     * 检查申请单
     */
    var vaa01 = $("#vaa01").val();
    var vac01 = $("#vac01").val();
    var temp_vbq = {};
    temp_vbq.vbq01 = count;
    temp_vbq.vaa01 = vaa01;
    temp_vbq.vaa07 = vac01;
    temp_vbq.acf01 = "1";
    temp_vbq.vap01 = "0";
    temp_vbq.vbq07 = "0";
    temp_vbq.bak01a = bck01;
    temp_vbq.bak01b = bck01;
    temp_vbq.bce03a = bce03;
    temp_vbq.bce01a = bce01;
    temp_vbq.vbq27 = $(".e_jianchamudi").val();
    temp_vbq.vbq28 = $(".e_linchuangzhenduan").val();
    temp_vbq.vbq29 = $(".e_binglizhaiyao").val();
    temp_vbq.vbq30 = $(".e_fuzhujiancha").val();
    vbq1.push(temp_vbq);

    $("#"+tableId+" tbody tr").each(function(i)
    {
        var tdArr = $(this);
        var flag = tdArr.find(".jiancha_yznr").val().replace(/[\r\n]/g,""); // 医嘱内容
        if (flag && flag.trim()!='')
        {
            // 医嘱类别
            var bda01 = "E";
            var zu = tdArr.find(".jiancha_zu").text();
            if (zu != "") // 同组
            {
                zuValue++;
            }
            if (i==0)
            {
                // vao1

                var diagnose = $(".main-header-search-input .bootstrap-tagsinput").children("span");
                var vaoLength =diagnose.length;
                for (var i = 0; i < vaoLength; i++)
                {
                    var vao1t = {};
                    var temp = $(diagnose[i]).text();
                    var str = $(diagnose[i]).attr("data-info");
                    var dobj = JSON.parse(str);
                    vao1t = $.extend(vao1t,dobj);
//					if (dobj.cam01)
//					{
//						vao1t.cam01 = dobj.cam01;
//						vao1t.bak01a = "0";// 疾病id-
//					}
//					else if (dobj.bak01)
//					{
//						vao1t.cam01 = "0";
//						vao1t.bak01a = dobj.bak01;// 疾病id-
//					}
                    if (str == -999)// 如果为手动添加的疾病
                    {
                        vao1t.cam01 = cam1Map[temp];
                    }

                    vao1t.vao15 = temp;
                    // vao1t.cam01 = id;
                    vao1t.cbmid = count;
                    vao1t.vaa01 = vaa01;
                    vao1t.vaa07 = vac01;
                    vao1t.acf01 = "1";
                    vao1t.vao06 = "1";// 诊断次讯
                    vao1t.vao07 = "1";// 0=初步诊断, 1=正常诊断
                    vao1t.vao10 = "0";// 0=西医, 1=中医
                    vao1t.vao11 = "1";// 1=门诊诊断, 2=入院诊断, 3=出院诊断, 4=, 5=医院感染,
                    // 6=病理诊断, 7=损伤中毒, 8=术前诊断, 9=术后诊断, 10=并发症,
                    // 11=病原学诊断，12＝尸检主要诊断
                    // vao1t.bak01a = "0";// 疾病id-
                    vao1t.vao18 = "0";// 描述: 1=疑诊, 其它正常
                    vao1t.vao22 = "1";// 描述: 0:其它地方诊断 1：医嘱单诊断 2:记账单诊断
                    vao1.push(vao1t);
                }
            }
            // cbm1
            var cbm1t = {};
            cbm1t.cbmid = count;
            cbm1t.vaa01 = vaa01;
            cbm1t.vaa07 = vac01;
            cbm1t.vap01 = 0;
            cbm1t.acf01 = 1;
            cbm1t.cbm06 = 9;// 描述: 性质: 0:不区分中、西药处方 1=西、成药, 2=中药, 3=手术记录, 4 =
            // 成药,5=卫材, 9=其他
            var cbm07 = $("#"+tableId).parents(".tab-pane").find(".tscf").val();
            cbm1t.cbm07 = cbm07;// 1=普通, 2=急诊, 3=儿童, 4=麻醉, 5=第一类精神药品, 6=第二类精神药品,
            // 7=放射药品,8=毒性药品,9=检查,10=检验,11=手术,12=治疗,99=其它
            cbm1t.bjw02 = "";// 处方分类
            cbm1t.iai03 = "";// 医疗类别编码
            cbm1t.bck01a = 0;// 病区id
            cbm1t.bck01b = bck01;// 病人科室id
            cbm1t.bck01c = $("#kaidankeshi").val();// 开单科室id
            cbm1t.cbm19 = $("#"+tableId).parents(".tab-pane").find(".zfbs").val();// 状态
            // var dataInfo = JSON.parse($(this).attr('data-info'));
            // cbm1t.total = (dataInfo.price) *
            // (tdArr.eq(9).find("input:eq(0)").val());
            cbm1.push(cbm1t);
            // 检查
            var temp1 = configData(tdArr, vaa01, vac01, count);
            temp1.lroute = "0";
            temp1.vaf11 = "2" // 长嘱还是临嘱
            temp1.vaf14 = "";// ???血浆、血清
            temp1.vaf22 = tdArr.find(".jiancha_yznr").val().replace(/[\r\n]/g,""); // 医嘱内容
            temp1.vaf32 = "0";// 正常还是给药途径
            temp1.bda01 = bda01;//
            temp1.bda01a = bda01;//
            temp1.rownr = "0";
            temp1.rcurrent = "0";
            temp1.biw02 = ""; // 用药目的
            temp1.bbx01 = tdArr.find(".jiancha_yznr").next().val(); // 诊疗项目ID---
            temp1.bby01 = 0; // 收费项目ID---
            temp1.vaf27=tdArr.find(".jiancha_pc").find("select").val(); //频次id
            temp1.vaf26=tdArr.find(".jiancha_pc").find("select option:selected").text(); //频次文本
            temp1.vaf17 = tdArr.find(".jiancha_yyts").val(); // 用药天数
            temp1.vaf28 = 0; //
            temp1.vaf18 = 0; //
            temp1.vaf20 = 0; //
            temp1.vaf34 = 0; //
            temp1.vaf21 = tdArr.find(".jiancha_zl").val().trim(); // 数量
            if (!n.test(temp1.vaf21))
            {
                validRestult = "检查总量必须为数字";
                validFlg = false;
                return false;
            }
            temp1.bck01b = tdArr.find(".jiancha_zxks").find("select option:selected").val();// 执行科室ID
            temp1.vaf58 = tdArr.find(".jiancha_zxxz").find("select option:selected").attr("id");// 执行性质
            temp1.vaf61 = 0;// 首次
            temp1.vaf59 = zu;// 组号
            temp1.vaf35 = tdArr.find(".jiancha_jinji").attr("data-value");// 紧急
            temp1.vaf23 = tdArr.find(".jiancha_yszt").val() == "" ? "" : tdArr.find(".jiancha_yszt").val();// 医师嘱托
            temp1.vaf55 = tdArr.find(".jiancha_yzbz").val() == "" ? "" : tdArr.find(".jiancha_yzbz").val();// 医嘱备注
            temp1.vaf31 = tdArr.find(".jiancha_jjxz").find("select option:selected").val();// 计价性质
            temp1.vaf30 = tdArr.find(".jiancha_zxfa").val() == "" ? "" : tdArr.find(".jiancha_zxfa").val();// 执行方案
            var bce1Info = tdArr.find(".jiancha_kzys").find("option:selected");
            temp1.bce01a = bce1Info.val();// bce01a
            temp1.bce02a = bce1Info.attr("id");// bce02a
            temp1.bce03a = bce1Info.text();// bce03a
            temp1.bck01c = tdArr.find(".jiancha_kzks").find("select").val();// jiancha_kzks
            vaf1.push(temp1);
            var bci07n = tdArr.attr("data-bci07");
            var location_code = "";
            var location_name = "";
            if(bci07n)
            {
                bci07n = JSON.parse(bci07n);
                if(bci07n.length<1){
                    layer.alert(temp1.vaf22+"没有计价信息，请重新开！");
                    validFlg = false;
                    return false;
                }
                for(var x = 0;x<bci07n.length;x++)
                {
                    var temp2 = configData(tdArr, vaa01, vac01, count);
                    temp2.lroute = "0";
                    temp2.vaf11 = "2" // 长嘱还是临嘱
                    temp2.vaf14 = bci07n[x].bci06;//
                    temp2.vaf15 = replaceAll(replaceAll(bci07n[x].bci07,"<span>",""),"</span>","");//
                    var vaf22 = tdArr.find(".jiancha_yznr").val().replace(/[\r\n]/g,""); // 医嘱内容
                    temp2.vaf22 =  vaf22.split(":")[0]; // 医嘱内容
                    temp2.vaf32 = "0";// 正常还是给药途径
                    temp2.bda01 = bda01;//
                    temp2.bda01a = bda01;//
                    temp2.rownr = x+1+"";
                    temp2.rcurrent = "0";
                    temp2.biw02 = ""; // 用药目的
                    temp2.bbx01 = tdArr.find(".jiancha_yznr").next().val(); // 诊疗项目ID---
                    temp2.bby01 = 0; // 收费项目ID---
                    temp1.vaf27=tdArr.find(".jiancha_pc").find("select option:selected").attr("id"); //频次id
                    temp1.vaf26=tdArr.find(".jiancha_pc").find("select option:selected").text(); //频次文本
                    temp1.vaf17 = tdArr.find(".jiancha_yyts").val(); // 用药天数
                    temp2.vaf28 = 0; //
                    temp2.vaf18 = 0; //
                    temp2.vaf20 = 0; //
                    temp2.vaf34 = 0; //
                    temp2.vaf21 = tdArr.find(".jiancha_zl").val().trim(); // 数量
                    if (!n.test(temp1.vaf21))
                    {
                        validRestult = "检查总量必须为数字";
                        validFlg = false;
                        return false;
                    }
                    temp2.bck01b = tdArr.find(".jiancha_zxks").find("select option:selected").val();// 执行科室ID
                    temp2.vaf58 = tdArr.find(".jiancha_zxxz").find("select option:selected").attr("id");// 执行性质
                    temp2.vaf61 = 0;// 首次
                    temp2.vaf59 = zu;// 组号
                    temp2.vaf35 = tdArr.find(".jianyan_jinji").attr("data-value");// 紧急
                    temp2.vaf23 = tdArr.find(".jiancha_yszt").val() == "" ? "" : tdArr.find(".jiancha_yszt").val();// 医师嘱托
                    temp2.vaf55 = tdArr.find(".jiancha_yzbz").val() == "" ? "" : tdArr.find(".jiancha_yzbz").val();// 医嘱备注
                    temp2.vaf31 = tdArr.find(".jiancha_jjxz").find("select option:selected").val();// 计价性质
                    temp2.vaf30 = tdArr.find(".jiancha_zxfa").val() == "" ? "" : tdArr.find(".jiancha_zxfa").val();// 执行方案
                    var bce1Info = tdArr.find(".jiancha_kzys").find("option:selected");
                    temp2.bce01a = bce1Info.val();// bce01a
                    temp2.bce02a = bce1Info.attr("id");// bce02a
                    temp2.bce03a = bce1Info.text();// bce03a
                    temp2.bck01c = tdArr.find(".jiancha_kzks").find("select").val();// jiancha_kzks
                    location_code += ","+tdArr.find(".jiancha_yznr").next().val();
                    location_name += ","+bci07n[x].bci06;
                    vaf1.push(temp2);

                }
            }
            if ((valueArr['p_9999_9999_103']==1 || valueArr['p_9999_9999_103']=='1') && $("#patient_bdp02").text()!="自费")
            {
                //audit-davices
                var temp22 = {};
                temp22.lVAF06 = $("#vac01").val();
                temp22.lBBY01 = temp1.bby01;
                temp22.lBBX01 = temp1.bbx01;
                temp22.lVAF21 = temp1.vaf21;
                temp22.ACF01 = 1;
                temp22.BDA01 = temp1.bda01;
                temp22.lVAF22 = temp1.vaf22;
                temp22.vaf22b = 1;
                temp22.BCK01 = valueArr['p_100_105002_108'];
                temp22.lBCK03 = 'bck03';
                temp22.lBCK03F = 'bck03f';
                temp22.VAF17 = temp1.vaf17;
                temp22.VAF18 = "1";
                temp22.VAF26 = tdArr.find(".jiancha_pc").text();
                temp22.VAF27 = "1";
                temp22.VAF28 = temp1.vaf28;
                temp22.vaj23 = 1;
                temp22.vaj26 = 1;
                temp22.vaj27 = 1;
                temp22.VAF29 = '1';
                temp22.VAF58 = temp1.vaf58;
                temp22.Compound = 1;
                temp22.lBDU07 = "1";
                temp22.lBDU08 = "lBDU08";
                temp22.lBDU09 = "lBDU09";
                var take_frequence = tdArr.find(".jiancha_pc").find("select option:selected").attr("data-bdi03");
                $.ajax(
                    {
                        url : rootUrl + "/doctoradvice/inspectionadvicefeedetail",
                        type : "post",
                        dataType : "json",
                        data : temp22,
                        async : false,
                        success : function(data)
                        {
                            if (data && data.list && data.list.length>0)
                            {
                                for (var int = 0; int < data.list.length; int++)
                                {
                                    if(location_code && location_code.length>0)
                                    {
                                        location_code = location_code.substring(1, location_code.length);
                                        location_name = location_name.substring(1, location_name.length);
                                    }
                                    var advice = data.list[int];
                                    var advice_detail_obj =
                                        {
                                            'project_code' : advice.iah04,
                                            'hospital_code' : advice.bby01,
                                            'project_name' : advice.bby05,
                                            'standard_code' : '',
                                            'is_out_recip' : 0,
                                            'recipe_no' : hccode+count,
                                            'invoice_project' : '',
                                            'dose_form' : '',
                                            'medical_specification' : '',
                                            'price' : advice.bby25,
                                            'medical_number' : advice.vaf21,
                                            'dose_unit' : "",
                                            'amount' : advice.bby25,
                                            'use_day' : "",
                                            'single_dose_number' : "",
                                            'single_dose_unit' : "",
                                            'take_medical_number' : "",
                                            'take_medical_unit' : "",
                                            'dose_day' : "",
                                            'deliver_way' : '',
                                            'take_frequence' : take_frequence?take_frequence:"OTH.P",
                                            'location_code' : location_code,
                                            'location_name' : location_name
                                        }
                                    advice_details.push(advice_detail_obj);
                                }
                            }
                        }
                    });
            }
        }
    });
}

// 手术
function GetInfoFromTableS(tableId,vaf1, cbm1, vax1, vao1,vbf1,advice_details)
{
    var bck01a = bck01;
//	var count = 80;
    count++;
    $("#"+tableId+" tbody").each(function(i)
    {
        var tdArr = $(this);
        var flag = tdArr.find(".shoushu_yznr").val();
        if (flag && flag.trim()!='')
        {
            // 医嘱类别
            var bda01 = "S";
            var zu = count;
            if (i==0)
            {
                // vao1
                var diagnose = $(".main-header-search-input .bootstrap-tagsinput").children("span");
                var vaoLength =diagnose.length;
                for (var i = 0; i < vaoLength; i++)
                {
                    var vao1t = {};
                    var temp = $(diagnose[i]).text();
                    var str = $(diagnose[i]).attr("data-info");
                    var dobj = JSON.parse(str);
                    vao1t = $.extend(vao1t,dobj);
//					if (dobj.cam01)
//					{
//						vao1t.cam01 = dobj.cam01;
//						vao1t.bak01a = "0";// 疾病id-
//					}
//					else if (dobj.bak01)
//					{
//						vao1t.cam01 = "0";
//						vao1t.bak01a = dobj.bak01;// 疾病id-
//					}
                    if (str == -999)// 如果为手动添加的疾病
                    {
                        vao1t.cam01 = cam1Map[temp];
                    }

                    vao1t.vao15 = temp;
                    // vao1t.cam01 = id;
                    vao1t.cbmid = count;
                    vao1t.vaa01 = vaa01;
                    vao1t.vaa07 = vac01;
                    vao1t.acf01 = "1";
                    vao1t.vao06 = "1";// 诊断次讯
                    vao1t.vao07 = "1";// 0=初步诊断, 1=正常诊断
                    vao1t.vao10 = "0";// 0=西医, 1=中医
                    vao1t.vao11 = "1";// 1=门诊诊断, 2=入院诊断, 3=出院诊断, 4=, 5=医院感染,
                    // 6=病理诊断, 7=损伤中毒, 8=术前诊断, 9=术后诊断, 10=并发症,
                    // 11=病原学诊断，12＝尸检主要诊断
                    // vao1t.bak01a = "0";// 疾病id-
                    vao1t.vao18 = "0";// 描述: 1=疑诊, 其它正常
                    vao1t.vao22 = "1";// 描述: 0:其它地方诊断 1：医嘱单诊断 2:记账单诊断
                    vao1.push(vao1t);
                }
            }
            // cbm1
            var cbm1t = {};
            cbm1t.cbmid = count;
            cbm1t.vaa01 = vaa01;
            cbm1t.vaa07 = vac01;
            cbm1t.vap01 = 0;
            cbm1t.acf01 = 1;
            cbm1t.cbm06 = 3;// 描述: 性质: 0:不区分中、西药处方 1=西、成药, 2=中药, 3=手术记录, 4 =
            // 成药,5=卫材, 9=其他
            var cbm07 = $("#"+tableId).parents(".tab-pane").find(".tscf").val();
            cbm1t.cbm07 = cbm07;// 1=普通, 2=急诊, 3=儿童, 4=麻醉, 5=第一类精神药品, 6=第二类精神药品,
            // 7=放射药品,8=毒性药品,9=检查,10=检验,11=手术,12=治疗,99=其它
            cbm1t.bjw02 = "";// 处方分类
            cbm1t.iai03 = "";// 医疗类别编码
            cbm1t.bck01a = 0;// 病区id
            cbm1t.bck01b = bck01;// 病人科室id
            cbm1t.bck01c = $("#kaidankeshi").val();// 开单科室id
            cbm1t.cbm19 = $("#"+tableId).parents(".tab-pane").find(".zfbs").val();// 状态
            // var dataInfo = JSON.parse($(this).attr('data-info'));
            // cbm1t.total = (dataInfo.price) *
            // (tdArr.eq(9).find("input:eq(0)").val());
            cbm1.push(cbm1t);

            // 主要手术
            var temp1 = configData(tdArr, vaa01, vac01, count);
            var vaf22_1 = tdArr.find(".shoushu_yznr").val();
            if(vaf22_1){
                temp1.vaf22 = tdArr.find(".shoushu_yznr").val().replace(/[\r\n]/g,"");
            }
            temp1.bbx01 = tdArr.find(".shoushu_yznr").next().val();
            temp1.bby01 = 0;
            temp1.bda01 = bda01;
            temp1.bda01a = bda01;
            temp1.rownr = "0";
            temp1.vaf14 = tdArr.find(".shoushu_sssj").val();
            if (!temp1.vaf14)
            {
                validRestult = "手术时间不能为空";
                validFlg = false;
                return false;
            }
            temp1.lroute = "0";
            temp1.vaf11 = "2" // 长嘱还是临嘱
            temp1.vaf32 = "0";// 正常还是给药途径
            temp1.rcurrent = "0";
            temp1.vaf17 = 0;
            temp1.vaf28 = 0; //
            temp1.vaf18 = 0; //
            temp1.vaf20 = 0; //
            temp1.vaf34 = 0; //
            temp1.vaf21 = tdArr.find(".shoushu_zl").val();// 数量,可以为0.5个
            if (!n.test(temp1.vaf21))
            {
                validRestult = "手术总量必须为数字";
                validFlg = false;
                return false;
            }
            temp1.bck01b = tdArr.find(".shoushu_zxks").find("option:selected").val();// 执行科室ID
            if (!temp1.bck01b)
            {
                validRestult = "手术执行科室为必填项";
                validFlg = false;
                return false;
            }
            temp1.vaf58 = tdArr.find(".shoushu_zxxz").find("option:selected").attr("id");// 执行性质
            temp1.vaf26 = tdArr.find(".shoushu_pc").find("select option:selected").text();
            temp1.vaf59 = zu;// 组号
            temp1.vaf35 = tdArr.find(".shoushu_jinji").attr("data-value");// 紧急
            temp1.vaf61 = 0;// 首次
            temp1.vaf23 = tdArr.find(".shoushu_yszt").val() == "" ? "" : tdArr.find(".shoushu_yszt").val();// 医师嘱托
            temp1.vaf55 = tdArr.find(".shoushu_yzbz").val() == "" ? "" : tdArr.find(".shoushu_yzbz").val();// 医嘱备注
            temp1.vaf31 = tdArr.find(".shoushu_jjxz").find("select option:selected").val();// 计价性质
            temp1.vaf30 = tdArr.find(".shoushu_zxfa").val() == "" ? "" : tdArr.find(".shoushu_zxfa").val();// 执行方案
            var bce1Info = tdArr.find(".shoushu_kzys").find("option:selected");
            temp1.bce01a = bce1Info.val();// bce01a
            temp1.bce02a = bce1Info.attr("id");// bce02a
            temp1.bce03a = bce1Info.text();// bce03a
            temp1.bck01c = tdArr.find(".shoushu_kzks").find("select").val();// shoushu_kzks
            //部位
            temp1.vaf15 = tdArr.find(".shoushu_buwei").val();// shoushu_buwei

            vaf1.push(temp1);
            if ((valueArr['p_9999_9999_103']==1 || valueArr['p_9999_9999_103']=='1') && $("#patient_bdp02").text()!="自费")
            {
                //audit-davices
                var temp22 = {};
                temp22.lVAF06 = $("#vac01").val();
                temp22.lBBY01 = temp1.bby01;
                temp22.lBBX01 = temp1.bbx01;
                temp22.lVAF21 = temp1.vaf21;
                temp22.ACF01 = 1;
                temp22.BDA01 = temp1.bda01;
                temp22.lVAF22 = temp1.vaf22;
                temp22.vaf22b = 1;
                temp22.BCK01 = valueArr['p_100_105002_108'];
                temp22.lBCK03 = 'bck03';
                temp22.lBCK03F = 'bck03f';
                temp22.VAF17 = temp1.vaf17;
                temp22.VAF18 = "1";
                temp22.VAF26 = tdArr.find(".shoushu_pc").find("select option:selected").text();
                temp22.VAF27 = "1";
                temp22.VAF28 = temp1.vaf28;
                temp22.vaj23 = 1;
                temp22.vaj26 = 1;
                temp22.vaj27 = 1;
                temp22.VAF29 = '1';
                temp22.VAF58 = temp1.vaf58;
                temp22.Compound = 1;
                var take_frequence = tdArr.find(".shoushu_pc").find("select option:selected").attr("data-bdi03");
                $.ajax(
                    {
                        url : rootUrl + "/doctoradviceeditor/queryfeedetail",
                        type : "post",
                        dataType : "json",
                        data : temp22,
                        async : false,
                        success : function(data)
                        {
                            if (data && data.list && data.list.length>0)
                            {
                                for (var int = 0; int < data.list.length; int++)
                                {
                                    var advice = data.list[int];
                                    var advice_detail_obj =
                                        {
                                            'project_code' : advice.iah04,
                                            'hospital_code' : advice.bby01,
                                            'project_name' : advice.bby05,
                                            'standard_code' : '',
                                            'is_out_recip' : 0,
                                            'recipe_no' : hccode+count,
                                            'invoice_project' : '',
                                            'dose_form' : '',
                                            'medical_specification' : '',
                                            'price' : advice.bby25,
                                            'medical_number' : advice.vaf21,
                                            'dose_unit' : "",
                                            'amount' : advice.bby25,
                                            'use_day' : "",
                                            'single_dose_number' : "",
                                            'single_dose_unit' : "",
                                            'take_medical_number' : "",
                                            'take_medical_unit' : "",
                                            'dose_day' : "",
                                            'deliver_way' : '',
                                            'take_frequence' : take_frequence?take_frequence:"OTH.P",
                                            'location_code' : '',
                                            'location_name' : ''
                                        }
                                    advice_details.push(advice_detail_obj);
                                }
                            }
                        }
                    });
            }
            /**
             * 附加手术医嘱
             */
            var k = 1;
            $(".shoushu_fjss").each(function(j, ele)
            {
                if ($(ele).val())
                {
                    var temp99 = configData(tdArr, vaa01, vac01, count);
                    temp99.vaf22 = $(ele).val();
                    temp99.bbx01 = $(ele).next().val();
                    temp99.bby01 = 0;
                    temp99.bda01 = bda01;
                    temp99.bda01a = bda01;
                    temp99.rownr = k + "";
                    temp99.vaf14 = tdArr.find(".shoushu_sssj").val();
                    temp99.lroute = "0";
                    temp99.vaf11 = "2" // 长嘱还是临嘱
                    temp99.vaf32 = "0";// 正常还是给药途径
                    temp99.rcurrent = "0";
                    temp99.vaf17 = 0;
                    temp99.vaf28 = 0; //
                    temp99.vaf18 = 0; //
                    temp99.vaf20 = 0; //
                    temp99.vaf34 = 0; //
                    temp99.vaf21 = 1;// 数量
                    temp99.bck01b = tdArr.find(".shoushu_zxks").find("option:selected").val();// 执行科室ID
                    temp99.vaf58 = tdArr.find(".shoushu_zxxz").find("option:selected").attr("id");// 执行性质
                    temp99.vaf59 = zu;// 首次
                    temp99.vaf61 = 0;// 首次
                    var bce1Info = tdArr.find(".shoushu_kzys").find("option:selected");
                    temp99.bce01a = bce1Info.val();// bce01a
                    temp99.bce02a = bce1Info.attr("id");// bce02a
                    temp99.bce03a = bce1Info.text();// bce03a
                    temp99.bck01c = tdArr.find(".shoushu_kzks").find("select").val();// shoushu_kzks
                    k++;
                    vaf1.push(temp99);
                    if ((valueArr['p_9999_9999_103']==1 || valueArr['p_9999_9999_103']=='1') && $("#patient_bdp02").text()!="自费")
                    {
                        //audit-davices
                        var temp22 = {};
                        temp22.lVAF06 = $("#vac01").val();
                        temp22.lBBY01 = temp1.bby01;
                        temp22.lBBX01 = temp1.bbx01;
                        temp22.lVAF21 = temp1.vaf21;
                        temp22.ACF01 = 1;
                        temp22.BDA01 = temp1.bda01;
                        temp22.lVAF22 = temp1.vaf22;
                        temp22.vaf22b = 1;
                        temp22.BCK01 = valueArr['p_100_105002_108'];
                        temp22.lBCK03 = 'bck03';
                        temp22.lBCK03F = 'bck03f';
                        temp22.VAF17 = temp1.vaf17;
                        temp22.VAF18 = "1";
                        temp22.VAF26 = tdArr.find(".shoushu_pc").find("select option:selected").text();
                        temp22.VAF27 = "1";
                        temp22.VAF28 = temp1.vaf28;
                        temp22.vaj23 = 1;
                        temp22.vaj26 = 1;
                        temp22.vaj27 = 1;
                        temp22.VAF29 = '1';
                        temp22.VAF58 = temp1.vaf58;
                        temp22.Compound = 1;
                        var take_frequence = tdArr.find(".shoushu_pc").find("select option:selected").attr("data-bdi03");
                        $.ajax(
                            {
                                url : rootUrl + "/doctoradviceeditor/queryfeedetail",
                                type : "post",
                                dataType : "json",
                                data : temp22,
                                async : false,
                                success : function(data)
                                {
                                    if (data && data.list)
                                    {
                                        for (var int = 0; int < data.list.length; int++)
                                        {
                                            var advice = data.list[int];
                                            var advice_detail_obj =
                                                {
                                                    'project_code' : advice.iah04,
                                                    'hospital_code' : advice.bby01,
                                                    'project_name' : advice.bby05,
                                                    'standard_code' : '',
                                                    'is_out_recip' : 0,
                                                    'recipe_no' : hccode+count,
                                                    'invoice_project' : '',
                                                    'dose_form' : '',
                                                    'medical_specification' : '',
                                                    'price' : advice.bby25,
                                                    'medical_number' : advice.vaf21,
                                                    'dose_unit' : "",
                                                    'amount' : advice.bby25,
                                                    'use_day' : "",
                                                    'single_dose_number' : "",
                                                    'single_dose_unit' : "",
                                                    'take_medical_number' : "",
                                                    'take_medical_unit' : "",
                                                    'dose_day' : "",
                                                    'deliver_way' : '',
                                                    'take_frequence' : take_frequence?take_frequence:"OTH.P",
                                                    'location_code' : '',
                                                    'location_name' : ''
                                                }

                                            advice_details.push(advice_detail_obj);
                                        }
                                    }
                                }
                            });
                    }
                }
            });

            // 麻醉
            // var mazuiVal = tdArr.find(".shoushu_mzfs").find("select
            // option:selected").val();
//			var mazuiVal = tdArr.find(".shoushu_mzfs").find("input:checked").val();
            var mazuiVal = tdArr.find(".shoushu_mzfs").find("select").val();

            if (mazuiVal)
            {
                // var mazuiArr = tdArr.find(".shoushu_mzfs").find("select
                // option:selected").val().split("|"); //select
                var mazuiArr = mazuiVal.split("|"); // checkbox
                var temp3 = configData(tdArr, vaa01, vac01, count);
                // temp3.vaf22 = tdArr.find(".shoushu_mzfs").find("select
                // option:selected").text(); //select
//				temp3.vaf22 = tdArr.find(".shoushu_mzfs").find("input:checked").next().text(); // checkbox
                temp3.vaf22 = tdArr.find(".shoushu_mzfs").find("option:selected").text(); // checkbox
                temp3.bbx01 = mazuiArr[1];
                temp3.bby01 = 0;
                temp3.bda01 = mazuiArr[0];
                temp3.bda01a = bda01;
                temp3.rownr = k + "";
                temp3.vaf14 = tdArr.find(".shoushu_sssj").val();
                temp3.lroute = "0";
                temp3.vaf11 = "2" // 长嘱还是临嘱
                temp3.vaf32 = "0";// 正常还是给药途径
                temp3.rcurrent = "0";
                temp3.vaf17 = 0;
                temp3.vaf28 = 0; //
                temp3.vaf18 = 0; //
                temp3.vaf20 = 0; //
                temp3.vaf34 = 0; //
                temp3.vaf21 = 1;// 数量
                temp3.bck01b = tdArr.find(".shoushu_mzzx").find("option:selected").val();// 执行科室ID
                temp3.vaf58 = tdArr.find(".shoushu_zxxz").find("option:selected").attr("id");// 执行性质
                temp3.vaf59 = zu;// 组号
                temp3.vaf61 = 0;// 首次
                var bce1Info = tdArr.find(".shoushu_kzys").find("option:selected");
                temp3.bce01a = bce1Info.val();// bce01a
                temp3.bce02a = bce1Info.attr("id");// bce02a
                temp3.bce03a = bce1Info.text();// bce03a
                temp3.bck01c = tdArr.find(".shoushu_kzks").find("select").val();// shoushu_kzks
                vaf1.push(temp3);
            }

            // 手术人员
            var mm = 1;
            var ssryText = $(".shoushurenyuanHtml").each(function(i, ele)
            {
                if ($(ele).val())
                {
                    var vax = {};
                    vax.cbmid = count;
                    vax.vaa01 = vaa01;
                    vax.vaa07 = vac01;
                    vax.acf01 = 1;
                    vax.vaf59 = zu;
                    vax.rownr = 0;
                    vax.ace01 = '';
                    vax.bce01 = $(ele).find("option:selected").val();
                    vax.bce02 = $(ele).find("option:selected").attr("id");
                    vax.bce03 = $(ele).find("option:selected").text();
                    if (mm == 1)
                    {
                        vax.ace01 = '01';
                    }
                    else if (mm > 4)
                    {
                        vax.ace01 = '--';
                    }
                    else
                    {
                        vax.ace01 = '02';
                    }
                    vax1.push(vax);
                    mm++;
                }
            });
            //切口等级，乙肝，输血
            var obj1 = {}
            var i=1;
            var vbf071 = $("#"+tableId).find(".shoushu_qiekoudengji").find("option:selected").text();
            var vbf072 = $("#"+tableId).find(".shoushu_yigan").find("option:selected").text();
            var vbf073 = $("#"+tableId).find(".shoushu_shuxue").val();

            if(vbf071){
                obj1.vbf03 = "切口等级"       //切口等级
                obj1.vbf07=vbf071
                obj1.vbf05=i;
                i++
                vbf1.push(obj1);
            }
            if(vbf072){
                var obj2={};
                obj2.vbf03 = "乙肝"       //乙肝
                obj2.vbf07=vbf072
                obj2.vbf05=i;
                i++
                vbf1.push(obj2);
            }
            if(vbf073){
                var obj3={};
                obj3.vbf03 = "输血"       //输血
                obj3.vbf07=vbf073
                obj3.vbf05=i;
                i++
                vbf1.push(obj3);
            }



        }
    });
}

// 治疗
function GetInfoFromTableT(tableId,vaf1, cbm1, vax1, vao1,advice_details)
{
    var bck01a = bck01;
//	var count = 100;
    count++;
    var zuValue = 0;
    $("#"+tableId+" tbody tr").each(function(i,ele)
    {
        var tdArr = $(this);
        var flag = tdArr.find(".zhiliao_yznr").val().replace(/[\r\n]/g,""); // 医嘱内容
        if (flag && flag.trim()!='')
        {
//			var str = $(ele).attr("data-info");
//			var str_obj = JSON.parse(str);
            // 医嘱类别
//			var bda01 = str_obj.bda01;
            var bda01 = "T";
            var zu = tdArr.find(".zhiliao_zu").text();
            if (zu != "") // 非同组
            {
                zuValue++;
            }
            if (i==0)
            {
                // vao1
                var diagnose = $(".main-header-search-input .bootstrap-tagsinput").children("span");
                var vaoLength =diagnose.length;
                for (var i = 0; i < vaoLength; i++)
                {
                    var vao1t = {};
                    var temp = $(diagnose[i]).text();
                    var str = $(diagnose[i]).attr("data-info");
                    var dobj = JSON.parse(str);
                    vao1t = $.extend(vao1t,dobj);
//					if (dobj.cam01)
//					{
//						vao1t.cam01 = dobj.cam01;
//						vao1t.bak01a = "0";// 疾病id-
//					}
//					else if (dobj.bak01)
//					{
//						vao1t.cam01 = "0";
//						vao1t.bak01a = dobj.bak01;// 疾病id-
//					}
                    if (str == -999)// 如果为手动添加的疾病
                    {
                        vao1t.cam01 = cam1Map[temp];
                    }

                    vao1t.vao15 = temp;
                    // vao1t.cam01 = id;
                    vao1t.cbmid = count;
                    vao1t.vaa01 = vaa01;
                    vao1t.vaa07 = vac01;
                    vao1t.acf01 = "1";
                    vao1t.vao06 = "1";// 诊断次讯
                    vao1t.vao07 = "1";// 0=初步诊断, 1=正常诊断
                    vao1t.vao10 = "0";// 0=西医, 1=中医
                    vao1t.vao11 = "1";// 1=门诊诊断, 2=入院诊断, 3=出院诊断, 4=, 5=医院感染,
                    // 6=病理诊断, 7=损伤中毒, 8=术前诊断, 9=术后诊断, 10=并发症,
                    // 11=病原学诊断，12＝尸检主要诊断
                    // vao1t.bak01a = "0";// 疾病id-
                    vao1t.vao18 = "0";// 描述: 1=疑诊, 其它正常
                    vao1t.vao22 = "1";// 描述: 0:其它地方诊断 1：医嘱单诊断 2:记账单诊断
                    vao1.push(vao1t);
                }
            }
            // cbm1
            var cbm1t = {};
            cbm1t.cbmid = count;
            cbm1t.vaa01 = vaa01;
            cbm1t.vaa07 = vac01;
            cbm1t.vap01 = 0;
            cbm1t.acf01 = 1;
            cbm1t.cbm06 = 9;// 描述: 性质: 0:不区分中、西药处方 1=西、成药, 2=中药, 3=手术记录, 4 =
            // 成药,5=卫材, 9=其他
            var cbm07 = $("#"+tableId).parents(".tab-pane").find(".tscf").val();
            cbm1t.cbm07 = cbm07;// 1=普通, 2=急诊, 3=儿童, 4=麻醉, 5=第一类精神药品, 6=第二类精神药品,
            // 7=放射药品,8=毒性药品,9=检查,10=检验,11=手术,12=治疗,99=其它
            cbm1t.bjw02 = "";// 处方分类
            cbm1t.iai03 = "";// 医疗类别编码
            cbm1t.bck01a = 0;// 病区id
            cbm1t.bck01b = bck01;// 病人科室id
            cbm1t.bck01c = $("#kaidankeshi").val();// 开单科室id
            cbm1t.cbm19 = $("#"+tableId).parents(".tab-pane").find(".zfbs").val();// 状态
            // var dataInfo = JSON.parse($(this).attr('data-info'));
            // cbm1t.total = (dataInfo.price) *
            // (tdArr.eq(9).find("input:eq(0)").val());
            cbm1.push(cbm1t);
            // 治疗
            var temp1 = configData(tdArr, vaa01, vac01, count);
            temp1.lroute = "0";
            temp1.vaf11 = "2" // 长嘱还是临嘱
            temp1.vaf14 = "";// ???血浆、血清
            temp1.vaf22 = tdArr.find(".zhiliao_yznr").val().replace(/[\r\n]/g,""); // 医嘱内容
            temp1.vaf32 = "0";// 正常还是给药途径
            temp1.bda01 = bda01;//
            temp1.bda01a = bda01;//
            temp1.rownr = "0";
            temp1.rcurrent = "0";
            temp1.biw02 = ""; // 用药目的
            temp1.bbx01 = tdArr.find(".zhiliao_yznr").next().val(); // 诊疗项目ID---
            temp1.bby01 = 0; // 收费项目ID---
            temp1.vaf26 = tdArr.find(".zhiliao_pc").find("select option:selected").text(); //频次
            temp1.vaf17 = tdArr.find(".zhiliao_ts").val().trim(); // 用药天数
            /*
             * if(!n.test(temp1.vaf17)){ validRestult="治疗天数必须为数字";
             * validFlg=false; return false; }
             */
            temp1.vaf28 = 0; //
            temp1.vaf18 = 0; //
            temp1.vaf20 = 0; //
            temp1.vaf34 = 0; //
            temp1.vaf21 = tdArr.find(".zhiliao_zl").val().trim(); // 数量
            if (!nz.test(temp1.vaf21))
            {
                validRestult = "治疗总量必须为数字";
                validFlg = false;
                return false;
            }
            temp1.bck01b = tdArr.find(".zhiliao_zxks").find("select option:selected").val();// 执行科室ID
            temp1.vaf58 = tdArr.find(".zhiliao_zxxz").find("select option:selected").attr("id");// 执行性质
            temp1.vaf59 = zuValue;// 首次
            temp1.vaf61 = 0;// 首次
            temp1.vaf35 = tdArr.find(".zhiliao_jinji").attr("data-value");// 紧急
            temp1.vaf23 = tdArr.find(".zhiliao_yszt").val() == "" ? "" : tdArr.find(".zhiliao_yszt").val();// 医师嘱托
            temp1.vaf55 = tdArr.find(".zhiliao_yzbz").val() == "" ? "" : tdArr.find(".zhiliao_yzbz").val();// 医嘱备注
            temp1.vaf31= tdArr.find(".zhiliao_jjxz").find("select option:selected").val();// 计价性质
            temp1.vaf30 = tdArr.find(".zhiliao_zxfa").val() == "" ? "" : tdArr.find(".zhiliao_zxfa").val();// 执行方案
            var bce1Info = tdArr.find(".zhiliao_kzys").find("option:selected");
            temp1.bce01a = bce1Info.val();// bce01a
            temp1.bce02a = bce1Info.attr("id");// bce02a
            temp1.bce03a = bce1Info.text();// bce03a
            temp1.bgz01 = $("#"+tableId).parents(".tab-pane").find(".xmgs").val();
            temp1.bck01c = tdArr.find(".zhiliao_kzks").find("select").val();// zhiliao_kzks
            vaf1.push(temp1);
            var bci07n = tdArr.attr("data-bci07");
            var location_code = "";
            var location_name = "";
            if(bci07n)
            {
                bci07n = JSON.parse(bci07n);
                for(var x = 0;x<bci07n.length;x++)
                {
                    var temp2 = configData(tdArr, vaa01, vac01, count);
                    temp2.lroute = "0";
                    temp2.vaf11 = "2" // 长嘱还是临嘱
                    temp2.vaf14 = bci07n[x].bci06;//
                    temp2.vaf15 = bci07n[x].bci07;//
                    temp2.vaf22 = tdArr.find(".zhiliao_yznr").val().replace(/[\r\n]/g,""); // 医嘱内容
                    temp2.vaf32 = "0";// 正常还是给药途径
                    temp2.bda01 = bda01;//
                    temp2.bda01a = bda01;//
                    temp2.rownr = x+1+"";
                    temp2.rcurrent = "0";
                    temp2.biw02 = ""; // 用药目的
                    temp2.bbx01 = tdArr.find(".zhiliao_yznr").next().val(); // 诊疗项目ID---
                    temp2.bby01 = 0; // 收费项目ID---
//					temp1.vaf26 = tdArr.find(".zhiliao_pc").find("select option:selected").text(); //频次
                    temp2.vaf17 = tdArr.find(".zhiliao_ts").val().trim(); // 用药天数
                    temp2.vaf28 = 0; //
                    temp2.vaf18 = 0; //
                    temp2.vaf20 = 0; //
                    temp2.vaf34 = 0; //
                    temp2.vaf21 = tdArr.find(".zhiliao_zl").val().trim(); // 数量
                    if (!nz.test(temp1.vaf21))
                    {
                        validRestult = "治疗总量必须为数字";
                        validFlg = false;
                        return false;
                    }
                    temp2.bck01b = tdArr.find(".zhiliao_zxks").find("select option:selected").val();// 执行科室ID
                    temp2.vaf58 = tdArr.find(".zhiliao_zxxz").find("select option:selected").attr("id");// 执行性质
                    temp2.vaf61 = 0;// 首次
                    temp2.vaf59 = zu;// 组号
                    temp2.vaf35 = tdArr.find(".zhiliao_jinji").attr("data-value");// 紧急
                    temp2.vaf23 = tdArr.find(".zhiliao_yszt").val() == "" ? "" : tdArr.find(".jiancha_yszt").val();// 医师嘱托
                    temp2.vaf55 = tdArr.find(".zhiliao_yzbz").val() == "" ? "" : tdArr.find(".jiancha_yzbz").val();// 医嘱备注
                    temp2.vaf31 = tdArr.find(".zhiliao_jjxz").find("select option:selected").val();// 计价性质
                    temp2.vaf30 = tdArr.find(".zhiliao_zxfa").val() == "" ? "" : tdArr.find(".jiancha_zxfa").val();// 执行方案
                    var bce1Info = tdArr.find(".zhiliao_kzys").find("option:selected");
                    temp2.bce01a = bce1Info.val();// bce01a
                    temp2.bce02a = bce1Info.attr("id");// bce02a
                    temp2.bce03a = bce1Info.text();// bce03a
                    location_code += ","+tdArr.find(".jiancha_yznr").next().val();
                    location_name += ","+bci07n[x].bci06;
                    temp2.bck01c = tdArr.find(".zhiliao_kzks").find("select").val();// zhiliao_kzks
                    vaf1.push(temp2);
                }
            }
            if ((valueArr['p_9999_9999_103']==1 || valueArr['p_9999_9999_103']=='1') && $("#patient_bdp02").text()!="自费")
            {
                //audit-davices
                var temp22 = {};
                temp22.lVAF06 = $("#vac01").val();
                temp22.lBBY01 = temp1.bby01;
                temp22.lBBX01 = temp1.bbx01;
                temp22.lVAF21 = temp1.vaf21;
                temp22.ACF01 = 1;
                temp22.BDA01 = temp1.bda01;
                temp22.lVAF22 = temp1.vaf22;
                temp22.vaf22b = 1;
                temp22.BCK01 = valueArr['p_100_105002_108'];
                temp22.lBCK03 = 'bck03';
                temp22.lBCK03F = 'bck03f';
                temp22.VAF17 = temp1.vaf17;
                temp22.VAF18 = "1";
                temp22.VAF26 = tdArr.find(".zhiliao_pc").text();
                temp22.VAF27 = "1";
                temp22.VAF28 = temp1.vaf28;
                temp22.vaj23 = 1;
                temp22.vaj26 = 1;
                temp22.vaj27 = 1;
                temp22.VAF29 = '1';
                temp22.VAF58 = temp1.vaf58;
                temp22.Compound = 1;
                var take_frequence = tdArr.find(".zhiliao_pc").find("select option:selected").attr("data-bdi03");
                $.ajax(
                    {
                        url : rootUrl + "/doctoradviceeditor/queryfeedetail",
                        type : "post",
                        dataType : "json",
                        data : temp22,
                        async : false,
                        success : function(data)
                        {
                            if (data && data.list && data.list.length>0)
                            {
                                for (var int = 0; int < data.list.length; int++)
                                {
                                    var advice = data.list[int];
                                    var advice_detail_obj =
                                        {
                                            'project_code' : advice.iah04,
                                            'hospital_code' : advice.bby01,
                                            'project_name' : advice.bby05,
                                            'standard_code' : '',
                                            'is_out_recip' : 0,
                                            'recipe_no' : hccode+count,
                                            'invoice_project' : '',
                                            'dose_form' : '',
                                            'medical_specification' : '',
                                            'price' : advice.bby25,
                                            'medical_number' : advice.vaf21,
                                            'dose_unit' : "",
                                            'amount' : advice.bby25,
                                            'use_day' : "",
                                            'single_dose_number' : "",
                                            'single_dose_unit' : "",
                                            'take_medical_number' : "",
                                            'take_medical_unit' : "",
                                            'dose_day' : "",
                                            'deliver_way' : '',
                                            'take_frequence' : take_frequence?take_frequence:"OTH.P",
                                            'location_code' : location_code,
                                            'location_name' : location_name
                                        }
                                    advice_details.push(advice_detail_obj);
                                }
                            }
                        }
                    });
            }
        }
    });
}
// 材料
function GetInfoFromTable4(tableId,vaf1, cbm1, vax1, vao1,advice_details)
{
    var bck01a = bck01;
//	var count = 100;
    count++;
    var zuValue = 0;
    $("#"+tableId+" tbody tr").each(function(i,ele)
    {
        var tdArr = $(this);
//		var flag = tdArr.find(".cailiao_yznr").val(); // 医嘱内容
        var flag = tdArr.find(".cailiao_yznr").val().replace(/[\r\n]/g,""); // 医嘱内容
        if (flag && flag.trim()!='')
        {
            var str = $(ele).attr("data-info");
            var str_obj = JSON.parse(str);
            // 医嘱类别
            var bda01 = str_obj.bda01;
            var zu = tdArr.find(".cailiao_zu").text();
            if (zu != "") // 非同组
            {
                zuValue++;
            }
            if (i==0)
            {
                // vao1
                var diagnose = $(".main-header-search-input .bootstrap-tagsinput").children("span");
                var vaoLength =diagnose.length;
                for (var i = 0; i < vaoLength; i++)
                {
                    var vao1t = {};
                    var temp = $(diagnose[i]).text();
                    var str = $(diagnose[i]).attr("data-info");
                    var dobj = JSON.parse(str);
                    vao1t = $.extend(vao1t,dobj);
//					vao1t.bak01a = dobj.bak01;// 疾病id-
//					if (str == -999)// 如果为手动添加的疾病
//					{
//						vao1t.cam01 = cam1Map[temp];
//					}
//
                    vao1t.vao15 = temp;
                    // vao1t.cam01 = id;
                    vao1t.cbmid = count;
                    vao1t.vaa01 = vaa01;
                    vao1t.vaa07 = vac01;
                    vao1t.acf01 = "1";
                    vao1t.vao06 = "1";// 诊断次讯
                    vao1t.vao07 = "1";// 0=初步诊断, 1=正常诊断
                    vao1t.vao10 = "0";// 0=西医, 1=中医
                    vao1t.vao11 = "1";// 1=门诊诊断, 2=入院诊断, 3=出院诊断, 4=, 5=医院感染,
                    // 6=病理诊断, 7=损伤中毒, 8=术前诊断, 9=术后诊断, 10=并发症,
                    // 11=病原学诊断，12＝尸检主要诊断
                    // vao1t.bak01a = "0";// 疾病id-
                    vao1t.vao18 = "0";// 描述: 1=疑诊, 其它正常
                    vao1t.vao22 = "1";// 描述: 0:其它地方诊断 1：医嘱单诊断 2:记账单诊断
                    vao1.push(vao1t);
                }
            }
            // cbm1
            var cbm1t = {};
            cbm1t.cbmid = count;
            cbm1t.vaa01 = vaa01;
            cbm1t.vaa07 = vac01;
            cbm1t.vap01 = 0;
            cbm1t.acf01 = 1;
            cbm1t.cbm06 = 5;// 描述: 性质: 0:不区分中、西药处方 1=西、成药, 2=中药, 3=手术记录, 4 =
            // 成药,5=卫材, 9=其他
            var cbm07 = $("#"+tableId).parents(".tab-pane").find(".tscf").val();
            cbm1t.cbm07 = cbm07;// 1=普通, 2=急诊, 3=儿童, 4=麻醉, 5=第一类精神药品, 6=第二类精神药品,
            // 7=放射药品,8=毒性药品,9=检查,10=检验,11=手术,12=治疗,99=其它
            cbm1t.bjw02 = "";// 处方分类
            cbm1t.iai03 = "";// 医疗类别编码
            cbm1t.bck01a = 0;// 病区id
            cbm1t.bck01b = bck01;// 病人科室id
            cbm1t.bck01c = $("#kaidankeshi").val();// 开单科室id
            cbm1t.cbm19 = $("#"+tableId).parents(".tab-pane").find(".zfbs").val();// 状态
            // var dataInfo = JSON.parse($(this).attr('data-info'));
            // cbm1t.total = (dataInfo.price) *
            // (tdArr.eq(9).find("input:eq(0)").val());
            cbm1.push(cbm1t);
            // 治疗
            var temp1 = configData(tdArr, vaa01, vac01, count);
            temp1.lroute = "0";
            temp1.vaf11 = "2" // 长嘱还是临嘱
            temp1.vaf14 = "";// ???血浆、血清
            temp1.vaf22 = tdArr.find(".cailiao_yznr").val().replace(/[\r\n]/g,""); // 医嘱内容
            temp1.vaf32 = "0";// 正常还是给药途径
            temp1.bda01 = bda01;//
            temp1.bda01a = bda01;//
            temp1.rownr = "0";
            temp1.rcurrent = "0";
            temp1.biw02 = ""; // 用药目的
            temp1.bbx01 = tdArr.find(".cailiao_yznr").next().val(); // 诊疗项目ID---
            temp1.bby01 = tdArr.find(".cailiao_yznr").next().next().val();; // 收费项目ID---
            temp1.vaf26 = tdArr.find(".cailiao_pc").find("select option:selected").text(); //频次
            temp1.vaf17 = tdArr.find(".cailiao_ts").val().trim(); // 用药天数
            temp1.vaf35 = tdArr.find(".cailiao_jinji").attr("data-value");// 紧急
            /*
             * if(!n.test(temp1.vaf17)){ validRestult="治疗天数必须为数字";
             * validFlg=false; return false; }
             */
            temp1.vaf28 = 0; //
            temp1.vaf18 = 0; //
            temp1.vaf20 = 0; //
            temp1.vaf34 = 0; //
            temp1.vaf21 = tdArr.find(".cailiao_zl").val().trim(); // 数量
            if (!nz.test(temp1.vaf21))
            {
                validRestult = "材料总量必须为正整数";
                validFlg = false;
                return false;
            }

            temp1.bck01b = tdArr.find(".cailiao_zxks").val();// 执行科室ID
            temp1.vaf58 = tdArr.find(".cailiao_zxxz").find("select option:selected").attr("id");// 执行性质
            temp1.vaf59 = zuValue;// 首次
            temp1.vaf61 = 0;// 首次
            temp1.vaf23 = tdArr.find(".cailiao_yszt").val() == "" ? "" : tdArr.find(".cailiao_yszt").val();// 医师嘱托
            temp1.vaf55 = tdArr.find(".cailiao_yzbz").val() == "" ? "" : tdArr.find(".cailiao_yzbz").val();// 医嘱备注
            temp1.vaf31 = tdArr.find(".cailiao_jjxz").find("select option:selected").val();// 计价性质
            temp1.vaf30 = tdArr.find(".cailiao_zxfa").val() == "" ? "" : tdArr.find(".cailiao_zxfa").val();// 执行方案
            var bce1Info = tdArr.find(".cailiao_kzys").find("option:selected");
            temp1.bce01a = bce1Info.val();// bce01a
            temp1.bce02a = bce1Info.attr("id");// bce02a
            temp1.bce03a = bce1Info.text();// bce03a
            temp1.bgz01 = $("#"+tableId).parents(".tab-pane").find(".xmgs").val();
            temp1.bck01c = tdArr.find(".cailiao_kzks").find("select").val();// zhiliao_kzks
            vaf1.push(temp1);
        }
    });
}

/**
 * 组合vaf1公共基础数据
 *
 * @param vaa01
 * @param vac01
 * @param tableObj
 * @param i
 * @returns {___anonymous_vaf1t}
 */
function configData(tdArr, vaa01, vac01, count)
{
    var vaf1t = {};
    var zu = $(tdArr).eq(1).text();
    var bck01a = bck01;
    vaf1t.cbmid = count;
    vaf1t.vaf04 = "1";
    vaf1t.vaf06 = vac01;
    vaf1t.vaf07 = "0";
    vaf1t.bck01a = bck01a; //病人挂号科室
    vaf1t.bck01d = $("#kaidankeshi").val();
    vaf1t.vaf10 = "1";
    vaf1t.vaf53 = "-1";
    vaf1t.vaf59 = "1";
    vaf1t.vaf36 = $(tdArr).find('.layer-date').first().val(); // 开始时间
    vaf1t.lsign = "0";
    vaf1t.vaf31 = "0";
    vaf1t.vaf33 = "0";
    vaf1t.vco01 = "0";
    vaf1t.bce01h = "0";
    vaf1t.bce03h = "0";
    vaf1t.vaa01 = vaa01;
    vaf1t.bce01b = "0";
    vaf1t.vaf01b = "0";

    vaf1t.vaf27 = 0; //
    vaf1t.vaf28 = 0; //
    vaf1t.vaf34 = 0; //
    vaf1t.vaf35 = 0; //
    vaf1t.vaf51 = 0; // 申请iD
    vaf1t.vaf52 = 0; // 新开还是上传
    vaf1t.vaf54 = 0; // 是否忽略打印
    vaf1t.vaf62 = 0; //
    vaf1t.vaf75 = 0; //
    return vaf1t;
}
// 医嘱内容校验
function validYizhuInfo()
{

}


/**
 * 选择诊查费
 */
function zhenjin2(obj)
{
    $.ajax({
        url:rootUrl+"/clidoctor/queryHasZj",
        type:"get",
        dataType:"json",
        data:{vac01:$("#vac01").val(),hours:valueArr['p_9999_9999_95']},
        async:false,
        success:function(data)
        {
            var flag = data.map.flag;
            if(flag)
            {
                sendFlag = false;
                //查询诊查费列表
                var zjList;
                $.ajax({url:rootUrl+"/clidoctor/queryZjList",type:"get",async:false,dataType:"json",success:function(data){
                    zjList = data.list;
                }});
                laytplUrl(myurl + "/module/zhenjin.html",{}, function(data, html) {
                    zhenjin_index = layer.open({
                        type : 1,
                        // scrollbar : false,
                        title : "选择诊查费",
                        area : [ "500px", "500px"],
                        shade : 0.1,
                        maxmin : true,
                        content : html,
                        closeBtn : 1,
                        cancel:function(){
                            $(thisbutton).removeAttr("disabled");

                            layer.msg("医嘱发送已取消！",{time : 3000,
                                icon : 0,
                                skin : 'layui-layer-msg0'});
                        },
                        success : function() {
                            $("#zhenjin_table").empty();
                            $("#zhenjin_table").GridUnload();
                            jQuery("#zhenjin_table").jqGrid(
                                {
                                    data : zjList,
                                    datatype : "local",
                                    height : 'auto',
                                    width : 'auto',
                                    autowidth : true,
                                    autoheight : true,
                                    multiselect : true,
                                    multiboxonly:true,
                                    colModel : [
                                        {
                                            label:'项目名称',
                                            name : 'bby05',
                                            align : 'left',
                                            width:'600'
                                        },
                                        {
                                            name : 'bdn01',
                                            hidden : true
                                        },
                                        {
                                            name : 'bby01',
                                            hidden : true
                                        },
                                        {
                                            label : '数量',
                                            name : 'amount',
                                            align : "right",
                                            formatter : function(value, options, rData){
                                                if(value){
                                                    val =value;
                                                }else{
                                                    val=1;
                                                }

                                                return val;
                                            }
                                        },
                                        {
                                            label : '单价',
                                            name : 'bby25',
                                            align : "right"
                                        },
                                        {
                                            label : '金额',
                                            name : 'bby25',
                                            align : "right"
                                        }
                                    ],
                                    ondblClickRow : function(rowid, status)
                                    {
                                        var row = $("#zhenjin_table").jqGrid("getRowData", rowid);
                                    }
                                });
                            $("#zhenjin_cancle").on("click",function(){
                                var that =this;
                                $(thisbutton).removeAttr("disabled");
                                layer.close(zhenjin_index);
                                layer.msg("医嘱发送已取消！",{time : 3000,
                                    icon : 0,
                                    skin : 'layui-layer-msg0'});
                            });
                            //获取诊金数据,保存发送医嘱
                            addZhenji2(obj);
                        }
                    })

                });
            }
            else
            {
//				sendFlag = true;
                var zjAddList = [];
                obj.zjAddList = zjAddList;
//				sendAdviceAfterSave(obj);
                sendAdviceImmediately(obj);
            }
        }
    });
}

/**
 * 保存诊金费用1
 */
function addZhenji2(obj)
{
    var zjAddList = [];
    $("#add_zhenji").on("click",function(){
        var that =this;
        $(that).attr("disabled",true);
        var ids = $('#zhenjin_table').jqGrid('getGridParam','selarrrow');
        for (var int = 0; int < ids.length; int++)
        {
            zjAddList.push($("#zhenjin_table").jqGrid("getRowData", ids[int]));
        }
        obj.zjAddList = zjAddList;
//		sendAdviceAfterSave(obj);
        sendAdviceImmediately(obj);
    });
}
/*--------------------------------------------------发送如果弹出诊金框，点击确定按钮继续发送，否则取消发送------------------------------------------------------------*/
function sendAdviceByzhenjin(obj){
    debugger;
    //发送的时候选择诊金
    if (obj.isSend == "send")
    {
        if (valueArr['p_9999_9999_104']=="1")
        {
            //弹出诊金对话框,根据诊金选中来确定是否发送医嘱
            zhenjin2(obj);
        }else{
            var zjAddList = [];
            obj.zjAddList = zjAddList;
//			sendAdviceAfterSave(obj)
            sendAdviceImmediately(obj);
        }

    }else{
        //只是保存医嘱
        justSaveAdvice(obj);
    }


}
//保存医嘱方法
function justSaveAdvice(obj){
    var def = $.Deferred();
    $.ajax(
        {
            url : rootUrl + "/clinewadvice/clinicvaf1insert",
            type : "post",
            async : false,
            data : obj.data1,
            dataType : 'json',
            success : function(data)
            {
//				var t4 = new Date().getTime();
//			    console.log('保存遗嘱耗时'+(t4-t3)+'毫秒');
                if (data.result == "Success")
                {
                    def.resolve(data);
                    if (obj.isSend != "send"){
                        layer.msg("保存成功！",
                            {
                                time : 2000,
                                icon : 1,
                                skin : 'layui-layer-msg1'
                            });
                        // 关闭并刷新
                        var flag_url = getUrlParam("yiyuanId");
                        if(!flag_url){
                            closeAndRefresh();

                        }
                    }
                }
                else
                {

                    layer.alert(data.resultMsg,
                        {
                            icon : 0,
                        });
                    $(thisbutton).removeAttr("disabled");
                    def.reject();
                    return;
                }

            }
        });
    return def.promise();
}
//保存成功后发送
function sendAdviceAfterSave(obj){
    $.when(
        justSaveAdvice(obj) //先保存
    ).done(function (data) {
        //执行发送
        var list = data.list;
        obj.list = list;
        sendImmediately(obj);
//			var t5 = new Date().getTime();
//		    console.log('发送遗嘱耗时'+(t5-t4)+'毫秒');

    });
}
